android:imeOptions="actionDone"

把EditText的Ime Options属性设置成不同的值,Enter键上可以显示不同的文字或图案
actionNone : 回车键,按下后光标到下一行
actionSend : Send
actionNext : Next


actionDone : Done,隐藏软键盘,即使不是最后一个文本输入框

设置android:imeOptions="actionDone" 可能监听不到键盘的是事件KeyEvent.KEYCODE_DPAD_CENTER  或者KeyEvent.KEYCODE_ENTER事件

可以 实现 setOnEditorActionListener 的onEditorAction

EditorInfo的说明中能够找到。列举如下:

IME_ACTION_DONE
IME_ACTION_GO
IME_ACTION_NEXT
IME_ACTION_NONE
IME_ACTION_PREVIOUS
IME_ACTION_SEARCH
IME_ACTION_SEND
IME_ACTION_UNSPECIFIED

软键盘的Enter键默认显示的是“完成”文本,我们知道按Enter建表示前置工作已经准备完毕了,要去什么什么啦。比如,在一个搜索中,我们输入要搜索的文本,然后按Enter表示要去搜索了,但是默认的Enter键显示的是“完成”文本,看着不太合适,不符合搜索的语义,如果能显示“搜索”两个字或者显示一个表示搜索的图标多好。事实证明我们的想法是合理的,Android也为我们提供的这样的功能。通过设置android:imeOptions来改变默认的“完成”文本。这里举几个常用的常量值:

  1. actionUnspecified  未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED.效果:
  2. actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE 效果:
  3. actionGo 去往,对应常量EditorInfo.IME_ACTION_GO 效果:
  4. actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH 效果: 
  5. actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND 效果:
  6. actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT 效果:
  7. actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE 效果:

 private TextView.OnEditorActionListener mWriteListener = 
    new TextView.OnEditorActionListener() { 
    public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { 
        // If the action is a key-up event on the return key, send the message 
        if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_UP) { 
            String message = view.getText().toString(); 
            sendMessage(message); 
        } 
        if(D) Log.i(TAG, "END onEditorAction"); 
        return true; 
    } 
}; 

   public static final int KEYCODE_SHIFT_RIGHT     = 60;
    public static final int KEYCODE_TAB             = 61;
    public static final int KEYCODE_SPACE           = 62;
    public static final int KEYCODE_SYM             = 63;
    public static final int KEYCODE_EXPLORER        = 64;
    public static final int KEYCODE_ENVELOPE        = 65;
    public static final int KEYCODE_ENTER           = 66;
    public static final int KEYCODE_DEL             = 67;
    public static final int KEYCODE_GRAVE           = 68;
    public static final int KEYCODE_MINUS           = 69;
    public static final int KEYCODE_EQUALS          = 70;

原文地址:https://www.cnblogs.com/mingfeng002/p/3243082.html