imeoptions android,软键盘小记Android:imeOptions
1.actionUnspecified 未指定,對(duì)應(yīng)常量EditorInfo.IME_ACTION_UNSPECIFIED.
2.actionNone 沒有動(dòng)作,對(duì)應(yīng)常量EditorInfo.IME_ACTION_NONE
3.actionGo 去往,對(duì)應(yīng)常量EditorInfo.IME_ACTION_GO
4.actionSearch 搜索,對(duì)應(yīng)常量EditorInfo.IME_ACTION_SEARCH
5.actionSend 發(fā)送,對(duì)應(yīng)常量EditorInfo.IME_ACTION_SEND
6.actionNext 下一個(gè),對(duì)應(yīng)常量EditorInfo.IME_ACTION_NEXT
7.actionDone 完成,對(duì)應(yīng)常量EditorInfo.IME_ACTION_DONE
android鍵盤中的enter鍵圖標(biāo)是可以用EditText的android:imeOptions標(biāo)簽變更的。
顯示search圖標(biāo)需要設(shè)置為android:imeOptions="actionSearch",android:inputType="text"將鍵盤設(shè)置為文字輸入布局
則鍵盤中search按鈕正常出現(xiàn)。
捕捉編輯框軟鍵盤enter事件:
1)setOnKeyListener
2)OnEditorActionListener
實(shí)現(xiàn)android按下回車鍵便隱藏輸入鍵盤,有兩種方法:
1)如果布局是多個(gè)EditText,為每個(gè)EditText控件設(shè)置android:singleLine=”true”,彈出的軟盤輸入法中回車鍵為next,直到最后一個(gè)獲取焦點(diǎn)后顯示為Done,點(diǎn)擊Done后,軟盤輸入鍵盤便隱藏。或者將EditText的imeOptions屬性設(shè)置android:imeOptions=”actionDone”,則不管是不是最后一個(gè)EditText,點(diǎn)擊回車鍵即隱藏輸入法。
2)監(jiān)聽Enter的事件,編寫Enter的事件響應(yīng)。設(shè)置文本框的OnKeyListener,當(dāng)keyCode ==KeyEvent.KEYCODE_ENTER的時(shí)候,表明Enter鍵被按下,就可以編寫自己事件響應(yīng)功能了
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(), );
}
;
}
;
}
});
在某些時(shí)候用戶填寫完畢。就該直接觸發(fā)接下來的點(diǎn)擊事件:
/**
*
* @param et editText
* @param view 需要觸發(fā)事件的view IME_ACTION_SEND || paramInt == EditorInfo.IME_ACTION_DONE || paramInt == EditorInfo.IME_ACTION_NEXT
* 出發(fā)view 的點(diǎn)擊事件
* performClick() 模擬人的手去觸發(fā)點(diǎn)擊時(shí)間
*/
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;
}
});
}
總結(jié)
以上是生活随笔為你收集整理的imeoptions android,软键盘小记Android:imeOptions的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 脑袋里经常出现嗡嗡响是什么问题?
- 下一篇: 什么品种的芒果比较好吃?