1.在Layout文件中,给EditText文件添加属性android:imeOptions=""
属性值含义:
actionUnspecified:未指定
actionNone :没有动作
actionSearch: 搜索
actionSend: 发送
actionNext: 下一项
actionGo:去往
actionDone :完成
对应用到的常量:
EditorInfo.IME_ACTION_UNSPECIFIED
EditorInfo.IME_ACTION_NONE
EditorInfo.IME_ACTION_SEARCH
EditorInfo.IME_ACTION_SEND
EditorInfo.IME_ACTION_NEXT
EditorInfo.IME_ACTION_GO
EditorInfo.IME_ACTION_DONE
2.EditText添加监听器
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId==EditorInfo.IME_ACTION_SEND ||(event!=null&&event.getKeyCode()== KeyEvent.KEYCODE_ENTER))
//do something;