android:imeOptions指定了彈出鍵盤時右下角的按鍵的顯示文字,未指定時默認為回車圖標(biāo)。
android:imeOptions="flagNoExtractUi" //使軟鍵盤不全屏顯示,只占用一部分屏幕 同時,這個屬性還能控件軟鍵盤右下角按鍵的顯示內(nèi)容,默認情況下為回車鍵 android:imeOptions="actionNone" //輸入框右側(cè)不帶任何提示 android:imeOptions="actionGo" //右下角按鍵內(nèi)容為'開始' android:imeOptions="actionSearch" //右下角按鍵為放大鏡圖片,搜索 android:imeOptions="actionSend" //右下角按鍵內(nèi)容為'發(fā)送' android:imeOptions="actionNext" //右下角按鍵內(nèi)容為'下一步' android:imeOptions="actionDone" //右下角按鍵內(nèi)容為'完成'
詳細使用見 http://blog.csdn.net/caiwenfeng_for_23/article/details/37900503
當(dāng)然也需要對這個按鍵進行設(shè)置點擊事件:
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// do sth when pressed the enter key in the Soft InputMethod
}
});
但是在AlertDialog或這PoupWIndow的EditText當(dāng)調(diào)用requestFocus()方法的時候卻不會自動彈出鍵盤,
此時需要直接調(diào)用顯示鍵盤命令,當(dāng)editText獲取焦點的時候。
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
//pop.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
});
在必要的時候隱藏輸入法界面:
//隱藏輸入法界面
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(input.getWindowToken(), 0);