Android disable Enter key in soft keyboard

前端 未结 5 1511
花落未央
花落未央 2020-12-31 10:36

Can anyone tell me how to disable and enable the Enter key in the soft keyboard?

5条回答
  •  渐次进展
    2020-12-31 11:18

    Attach OnEditorActionListener to your text field and return true from its onEditorAction method, when actionId is equal to IME_ACTION_DONE. This will prevent soft keyboard from hiding:

    EditText txtEdit = (EditText) findViewById(R.id.txtEdit);
    txtEdit.setOnEditorActionListener(new OnEditorActionListener() {
    
      public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
          // your additional processing... 
          return true;
        } else {
          return false;
        }
      }
    });
    

    Refer this LINK.

提交回复
热议问题