安卓:如何防止在对话框显示时弹出键盘

7
有没有办法在对话框弹出时防止键盘自动出现?
以下是我的对话框代码:
final Dialog dialog = new Dialog(this);
                    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                    dialog.setContentView(R.layout.shopping_cart_confirm_dialog);
                    TextView txtConfirmEmail = (TextView)dialog.findViewById(R.id.txtConfirmEmail);
                    ...
                    dialog.show();

非常感谢。
2个回答

21

试试这个

dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

0

使用InputMethodManager,您应该能够隐藏键盘。

检查hideSoftInputFromWindow。它接受一个由窗口令牌返回的参数。

View.getWindowToken()


InputMethodManager mgr=(InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(dialog.getWindow().getWindowToken(), 0);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接