How to display custom keyboard when clicking on edittext in android

后端 未结 6 572
日久生厌
日久生厌 2020-12-29 13:33

I have a custom keyboard in my application. question is How to didplay this keyboard when click on the edittext.I an using setonfocuschangre listener ,now the custon keyboa

6条回答
  •  臣服心动
    2020-12-29 13:44

    Initiate the InputConnection of your edit text and create methods to delete and enter texts when your custom keyboard view is performed with any user actions.

    Declare inputConnection on the activity onCreate method as below;

    InputConnection inputConnection = editText.onCreateInputConnection(new EditorInfo());
    

    When you enter any text execute the below code.

    inputConnection.commitText(text, 1);
    

    When you click the clear / backspace button execute the below code.

    if (TextUtils.isEmpty(inputConnection.getSelectedText(0))) {
        inputConnection.deleteSurroundingText(1, 0);
    } else {
        inputConnection.commitText("", 1);
    }
    

提交回复
热议问题