如何在安卓系统中更改软键盘“Enter”按钮的文本?

8

我希望将软键盘上的“Enter”键文本改为“完成”。

有没有办法更改 Android 设备上软键盘的 Enter 键文本?请建议一下,如果有任何想法。

提前感谢您。


这个链接提供了另一种方法。https://dev59.com/K3I-5IYBdhLWcg3wTWj4#27035249 - Zar E Ahmer
2个回答

12

在 XML 中,为 editText 添加

android:imeOptions="actionDone"

3
设置 setOnEditorActionListener()。 - Erik B

3
    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;
            }
        };

请在您的答案中添加一些解释。仅有代码的答案对未来的读者没有任何帮助。 - Madhur Bhaiya
谢谢您的建议。我会添加一份说明。 - Rajneesh Shukla

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接