简体   繁体   English

Android禁用软键盘中的Enter键

[英]Android disable Enter key in soft keyboard

谁能告诉我如何在软键盘中禁用和启用Enter键?

just go to your xml and put this attribute in EditText 只需转到您的xml并将此属性放在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 . 附加OnEditorActionListener到您的文本字段,并从它的返回true onEditorAction方法,当actionId等于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: EditText's布局中,输入如下内容:

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 试试这个,imeOptions = actionDone

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

我知道这个问题已经很老了,但是禁用enter键的一种简单方法是在EditText中设置android:maxLines =“1”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM