EditText cursor moves with input

  The current requirements are as follows: Click a button to pop up a custom keyboard, and at the same time, the cursor needs to be displayed in the input box, the soft keyboard needs to be hidden, and input on the custom keyboard, the cursor can continuously move backward, and it can continuously move forward when deleting characters .


//Click to get cursor position and focus
plateNumberTxt.setText("");
plateNumberTxt.requestFocus();


//The input content continues to gain focus
plateNumberTxt.append(arg);
plateNumberTxt.setSelection(plateNumberTxt.length());
plateNumberTxt.requestFocus();


// shield soft keyboard
if (android.os.Build.VERSION.SDK_INT <= 10) {
    plateNumberTxt.setInputType(InputType.TYPE_NULL);
} else {
    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    try {
        Class<EditText> cls = EditText.class;
        Method method = cls.getMethod("setShowSoftInputOnFocus", boolean.class);
        method.setAccessible(true);
        method.invoke(plateNumberTxt, false);
    } catch (Exception e) {
        e.printStackTrace ();
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326226147&siteId=291194637