Android disable Enter key in soft keyboard

白昼怎懂夜的黑 提交于 2019-11-30 12:17:51

just go to your xml and put this attribute in EditText

android:singleLine="true"

and your enter key will be gone

Shankar Agarwal

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.

In the EditText's layout put something like this:

android:digits="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ,"

You can also enumerate the rest of the symbols that you would like to be able to enter there, but not the enter key.

Try this, together imeOptions = actionDone

<EditText 
   android:id="@+id/edittext_done"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:imeOptions="actionDone"
   android:maxLines="1"/>

I know this question is quite old but an easy way of disabling the enter key is to set android:maxLines="1" in your EditText.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!