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
android鍵盤中的enter鍵圖標是可以用EditText的android:imeOptions標簽變更的。
顯示search圖標需要設置為android:imeOptions="actionSearch",android:inputType="text"將鍵盤設置為文字輸入布局
則鍵盤中search按鈕正常出現。
捕捉編輯框軟鍵盤enter事件:
1)setOnKeyListener
2)OnEditorActionListener
實現android按下回車鍵便隱藏輸入鍵盤,有兩種方法:
1)如果布局是多個EditText,為每個EditText控件設置android:singleLine=”true”,彈出的軟盤輸入法中回車鍵為next,直到最后一個獲取焦點后顯示為Done,點擊Done后,軟盤輸入鍵盤便隱藏。或者將EditText的imeOptions屬性設置android:imeOptions=”actionDone”,則不管是不是最后一個EditText,點擊回車鍵即隱藏輸入法。
2)監聽Enter的事件,編寫Enter的事件響應。設置文本框的OnKeyListener,當keyCode ==KeyEvent.KEYCODE_ENTER的時候,表明Enter鍵被按下,就可以編寫自己事件響應功能了
emailPwd.setOnKeyListener(View.OnKeyListener(){
onKey(View v, keyCode, KeyEvent event) {
(keyCode == KeyEvent.){
InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.);
(imm.isActive()){
imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), );
}
;
}
;
}
});
在某些時候用戶填寫完畢。就該直接觸發接下來的點擊事件:
/**
*
* @param et editText
* @param view 需要觸發事件的view IME_ACTION_SEND || paramInt == EditorInfo.IME_ACTION_DONE || paramInt == EditorInfo.IME_ACTION_NEXT
* 出發view 的點擊事件
* performClick() 模擬人的手去觸發點擊時間
*/
public static void setEtActionClick(EditText et, final View view) {
et.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView paramTextView, int paramInt,
KeyEvent paramKeyEvent) {
if (paramInt == EditorInfo.IME_ACTION_SEND || paramInt == EditorInfo.IME_ACTION_DONE || paramInt == EditorInfo.IME_ACTION_NEXT)// || (paramKeyEvent != null && paramKeyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER))
return view.performClick();
return false;
}
});
}