edittext 设置右下角回车键文字和响应事件
xml文件
<EditText
android:singleLine="true"
android:imeOptions="actionSend"/>
最后一行是设置回车键的设置,singleline不加的话设置不会生效
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
事件捕捉
edtClassId.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
if ((actionId == EditorInfo.IME_ACTION_SEND ) || (keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
if (!edtClassId.getText().toString().trim().equals("")) {
//todo
}
return true;
}
return false;
}
});