以改为搜索为例,xml 文件中添加:
android:imeOptions="actionSearch"
android:singleLine="true"
代码中监听:
et_text.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if ((actionId == EditorInfo.IME_ACTION_SEARCH)) {
//搜索
return true;
}
return false;
}
});
下面是对应关系
actionUnspecified 未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED.
actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE
actionGo 去往,对应常量EditorInfo.IME_ACTION_GO
actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH
actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND
actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT
actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE