Keyboard is not being hidden when AlertDialog is dismissed
I have extended AlertDialog with my class that displays my XML layout. I don't use AlertDialog's standard buttons, I have my own OK and Cancel buttons. Listener for them calls dismiss()
. The problem is if I was editing EditText's contents and then pressed OK (it's an Android 3.1 tablet, keyboard doesn't prevent me from interacting with the dialog), the dialog will hide but keyboard won't, it'll stay in background. What could be the reason and how to fix it?
Here's a constructor of my dialog, to give the idea:
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();
}
});
}
您可以强制使用软键盘隐藏:
try {
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
} catch (Exception e) {}
链接地址: http://www.djcxy.com/p/93332.html
上一篇: 如何在活动负载上打开输入键盘