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

后端 未结 2 587
借酒劲吻你
借酒劲吻你 2021-01-18 09:31

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 sugg

2条回答
  •  清歌不尽
    2021-01-18 10:19

        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.
    
    
    
     
    
            
    

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

提交回复
热议问题