开发者

Android disable Enter key in soft keyboard

开发者 https://www.devze.com 2023-04-01 23:36 出处:网络
Can anyone tell me how t开发者_JS百科o disable and enable the Enter key in the soft keyboard?just go to your xml and put this attribute in EditText

Can anyone tell me how t开发者_JS百科o disable and enable the Enter key in the soft keyboard?


just go to your xml and put this attribute in EditText

android:singleLine="true"

and your enter key will be gone


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.


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"/>


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消