How to display custom keyboard when clicking on edittext in android

后端 未结 6 562
日久生厌
日久生厌 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:52

    You can try something like this

        edittext.setOnClickListener(new OnClickListener() {
                        // NOTE By setting the on click listener, we can show the custom keyboard again,
                       // by tapping on an edit box that already had focus (but that had the keyboard hidden).
                        @Override public void onClick(View v) {
                            showCustomKeyboard(v);
                        }
              });
    
    
              // Disable standard keyboard hard way
              // NOTE There is also an easy way: 'edittext.setInputType(InputType.TYPE_NULL)' 
             // (but you will not have a cursor, and no 'edittext.setCursorVisible(true)' doesn't work )
                    edittext.setOnTouchListener(new OnTouchListener() {
                        @Override public boolean onTouch(View v, MotionEvent event) {
                            EditText edittext = (EditText) v;
                            int inType = edittext.getInputType();       // Backup the input type
                            edittext.setInputType(InputType.TYPE_NULL); // Disable standard keyboard
                            edittext.onTouchEvent(event);               // Call native handler
                            edittext.setInputType(inType);              // Restore input type
                            return true; // Consume touch event
                        }
                    });
    
    
            // Disable spell check (hex strings look like words to Android)
            edittext.setInputType(edittext.getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    

    For more info check here

提交回复
热议问题