gpt4 book ai didi

android - 关闭 AlertDialog 时键盘未被隐藏

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:05:53 27 4
gpt4 key购买 nike

我用显示我的 XML 布局的类扩展了 AlertDialog。我不使用 AlertDialog 的标准按钮,我有自己的确定和取消按钮。他们的监听器调用 dismiss()。问题是如果我正在编辑 EditText 的内容然后按确定(它是 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();
}
});
}

最佳答案

您可以强制隐藏软键盘:

    try {
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
} catch (Exception e) {}

关于android - 关闭 AlertDialog 时键盘未被隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12513352/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com