Keep soft keyboard open when enter key is pressed

前端 未结 1 415
不思量自难忘°
不思量自难忘° 2020-12-06 13:21

Well, I\'m trying to prevent the soft keyboard from closing when the user press the \"ok\" button after editing a text field. Actually, what i\'m trying to achieve is : when

相关标签:
1条回答
  • 2020-12-06 13:54

    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;
        }
      }
    
    });
    
    0 讨论(0)
提交回复
热议问题