我用我的类扩展了AlertDialog,显示了我的XML布局.我没有使用AlertDialog的标准按钮,我有自己的OK和Cancel按钮.监听他们的电话dismiss().问题是如果我正在编辑EditText的内容然后按下OK(这是一个Android 3.1平板电脑,键盘不会阻止我与对话框交互),对话框将隐藏但键盘不会,它将保留在后台.可能是什么原因以及如何解决?
这是我的对话框的构造函数,给出了这个想法:
public NetworkCameraParametersDialog(Context context ) {
super(context);
View content = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.dialog, null);
setView(content);
Button btnOk = (Button) content.findViewById(R.id.btn_Ok);
btnOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Some work
dismiss();
}
});
Button btnClose = (Button) content.findViewById(R.id.btn_Close);
btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
}
Run Code Online (Sandbox Code Playgroud)
您可以强制隐藏软键盘:
try {
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
} catch (Exception e) {}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2310 次 |
| 最近记录: |