1.问题描述:

  在自定义的AlertDialog 中添加了EditText组件,但运行时怎么点EditText都无法调出软键盘;

 

2.原因分析:

  一开始我以为EditText的focus属性没有设置好,但 添加了setFocusable() 和 setFocusableInTouchMode() 函数后还是不行;然后就觉得可能是父容器之类的参数可能没有设置好,上网搜了一下,果不其然...

 

3.解决办法:

  在后面添加两行代码,设置一下dialog的参数:

dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

  问题解决~

 

相关文章:

  • 2021-05-01
  • 2022-12-23
  • 2021-05-29
  • 2021-08-29
  • 2022-12-23
  • 2021-08-15
  • 2022-01-06
  • 2021-09-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2021-07-07
  • 2022-12-23
  • 2021-06-18
  • 2021-09-19
相关资源
相似解决方案