Android AlertDialog 无法弹出输入法

来源:互联网 发布:魔法王座神器升级数据 编辑:程序博客网 时间:2024/05/19 01:32

可能很多人都遇到这种问题,点击dialog的输入框无法弹出输入法,我就说说自己的解决方法

  • 先说说我的dialog使用方法
 final AlertDialog dialog = new AlertDialog.Builder(this).create();        dialog.show();        dialog.setCanceledOnTouchOutside(false);        dialog.setCancelable(true);        View v = View.inflate(this, R.layout.dialog_del_order, null);        dialog.getWindow().setContentView(v);

这是直接设置当前window的view,无需再自定义Dialog

  • 我的解决方法

//清楚flags,获取焦点
dialog.getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
//弹出输入法
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
“`

0 0