2016-03-14 4 views
0

У меня проблема с editText.setImeActionLabel. Он отлично работает на устройствах premarshmallow, но не работает на зефир.EditText setImeActionLabel не работает в android marshmallow

Вот мой код для справки,

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

Также Пробовал с вариантами раздувом,

EditorInfo.IME_ACTION_GO 
EditorInfo.IME_ACTION_DONE 
EditorInfo.IME_ACTION_NEXT 

Пожалуйста, наставит меня один такой же.

+0

Пожалуйста, проверьте [это] (http://stackoverflow.com/questions/1538331/android-cant-figure-how-to-use-setimeactionlabel) и [это] (http://stackoverflow.com/questions/ 26299861/edittext-input-method-action-not-working-when-setting-imeactionlabel) ответ. –

+0

Выше решение не работает, значок «Готово» заменяет значок поиска, но текст не отображается на нем. –

ответ

1

После долгих проб и ошибок, наконец, ниже решение работает для меня. набора ниже поля в Xml,

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

код в главном классе,

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

Надеется, что это поможет другим.

Смежные вопросы