Android imeOptions=“actionDone” not working

断了今生、忘了曾经 提交于 2019-12-03 09:25:11
Oat Anirut

Just add android:inputType="..." to your EditText. It will work!! :)

You should set OnEditorActionListener for the EditText to implement the action you want to perform when user clicks the "Done" in keyboard.

Thus, you need to write some code like:

password.setOnEditorActionListener(new OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            // Do whatever you want here
            return true;
        }
        return false;
    }
});

See the tutorial at android developer site

Qianqian is correct. Your code only listens for the button click event, not for the EditorAction event.

I want to add that some phone vendors may not properly implement the DONE action. I have tested this with a Lenovo A889 for example, and that phone never sends EditorInfo.IME_ACTION_DONEwhen you press done, it always sends EditorInfo.IME_ACTION_UNSPECIFIED so I actually end up with something like

myEditText.setOnEditorActionListener(new EditText.OnEditorActionListener() {
  @Override
  public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event)
  {
    boolean handled=false;

    // Some phones disregard the IME setting option in the xml, instead
    // they send IME_ACTION_UNSPECIFIED so we need to catch that
    if(EditorInfo.IME_ACTION_DONE==actionId || EditorInfo.IME_ACTION_UNSPECIFIED==actionId)
    {
      // do things here

      handled=true;
    }

    return handled;
  }
});

Also note the "handled" flag (Qianqian didn't explain that part). It might be that other OnEditorActionListeners higher up are listening for events of a different type. If your method returns false, that means you didn't handle this event and it will be passed on to others. If you return true that means you handled/consumed it and it will not be passed on to others.

influx

Use android:inputType="Yours" then

android:lines="1"
android:imeOptions="actionDone"

After trying many things, this is what worked for me:

    android:maxLines="1"
    android:inputType="text"
    android:imeOptions="actionDone"

You should set OnEditorActionListener for the EditText to implement the action you want to perform when user clicks the "Done" in keyboard.

just Add this to your attributes :

android:inputType="textPassword"

Doc: here

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