1

I am facing issue with editText.setImeActionLabel option. It's working fine on premarshmallow devices but not working on marshmallow.

Here is my code for reference,

edt_testIMEIoptions.setImeOptions(EditorInfo.IME_ACTION_DONE);
    edt_testIMEIoptions.setImeActionLabel("Login", EditorInfo.IME_ACTION_DONE);

    edt_testIMEIoptions.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                Toast.makeText(TestActivity.this, "Done called", Toast.LENGTH_SHORT).show();
                return true;
            }
            return false;
        }
    });

Also Tried with blow options,

EditorInfo.IME_ACTION_GO 
EditorInfo.IME_ACTION_DONE
EditorInfo.IME_ACTION_NEXT

Please guide me one the same.

Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
chetan mekha
  • 665
  • 6
  • 18
  • Please check [this](http://stackoverflow.com/questions/1538331/android-cant-figure-how-to-use-setimeactionlabel) and [this](http://stackoverflow.com/questions/26299861/edittext-input-method-action-not-working-when-setting-imeactionlabel) answer. – Amit Vaghela Mar 14 '16 at 10:40
  • Above solution not working, Done icon gets replace with search icon but text not appearing on it. – chetan mekha Mar 14 '16 at 10:47

1 Answers1

4

After lot of trial and error finally below solution work for me. set below field in XMl,

android:singleLine="true"
 android:imeOptions="actionDone"

Code in main class,

etPassword.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override

        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            /*
            after entering the password, When user clicks on done button,
            keyboard gets hide and clear the focus from the password edittext
             */

            if (event != null && event.getAction() != KeyEvent.ACTION_DOWN) {
                return false;
            } else if (actionId == EditorInfo.IME_ACTION_DONE
                    || event == null
                    || event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                etPassword.clearFocus();
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(etPassword.getWindowToken(), 0);
                // Your code                    
                return true;
            }

            return false;
        }
    });

Hope it will help others.

chetan mekha
  • 665
  • 6
  • 18