【问题标题】:How to change the Softkeyboard "Enter" button Text in android?如何更改 android 中的软键盘“Enter”按钮文本?
【发布时间】:2012-12-31 10:38:17
【问题描述】:

我想将软键盘设置为“输入”键文本为“完成”。 有什么办法可以改变安卓设备软键盘的回车键文本?如果有人有任何想法,请提出建议。

提前谢谢你。

【问题讨论】:

标签: android android-keypad


【解决方案1】:

editText 放在 XML 中

android:imeOptions="actionDone"

【讨论】:

  • 然后 setOnEditorActionListener()
【解决方案2】:
    Apply inputType and imeOptions tag in EditText. Here inputType property is the type of data to be inserted and imeOptions is the action. this action may be go to next edittext, search, enter etc. This property change the icon on bottom right corner of the soft keyboard.



 <EditText
            android:id="@+id/username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:hint="user name" />

        <EditText
            android:id="@+id/password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="password"
            android:inputType="numberPassword"
            android:imeOptions="actionSearch"/>

Java 代码

  EditText userName = findViewById(R.id.username);
                EditText password = findViewById(R.id.password);

// Set the action listener on editText

            userName.setOnEditorActionListener(editorActionListener);
            password.setOnEditorActionListener(editorActionListener);
        }

 // and based on the emeOptions define in EditText add listeners when the 
 //enter key key pressed in softKeyboad 

        private TextView.OnEditorActionListener editorActionListener = new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                switch (actionId){
                     case EditorInfo.IME_ACTION_NEXT:
                        Toast.makeText(MainActivity.this, "Next", Toast.LENGTH_SHORT).show();
                        break;

                    case EditorInfo.IME_ACTION_SEARCH:
                        Toast.makeText(MainActivity.this, "SEARCH", Toast.LENGTH_SHORT).show();
                        break;
                }
                return false;
            }
        };

【讨论】:

  • 请为您的答案添加一些解释。仅代码答案不会为未来的读者提供任何目的。
  • 感谢您的建议。我将添加一个解释。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-08
  • 1970-01-01
  • 2011-09-13
  • 2013-03-25
  • 2023-03-24
  • 2013-02-25
  • 1970-01-01
相关资源
最近更新 更多