How to change the Softkeyboard “Enter” button Text in android?

社会主义新天地 提交于 2019-12-01 23:32:35

问题


I want to set the softkeyboard to "Enter" key text to "Done". Is there any way to change the text of the enter key of the softkeyboard of the android device? Please suggest if anyone have any idea.

Thank you in advance.


回答1:


In XML for the editText put

android:imeOptions="actionDone"



回答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 Code

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


来源:https://stackoverflow.com/questions/14100482/how-to-change-the-softkeyboard-enter-button-text-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!