7

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

先感谢您。

4

2 回答 2

12

在 XML 中用于editTextput

android:imeOptions="actionDone"
于 2012-12-31T10:40:09.513 回答
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;
            }
        };
于 2018-11-01T09:59:54.353 回答