今天在做一个练习的时候,自定义了一个AlertDialog,其中有个EditText,在调试运行的时候,发现点击EditText无法弹出输入法,甚是着急。经各种XX引擎搜索之后,找到了答案。
<span style="line-height: 22.75px; color: rgb(0, 0, 0);"> getWindow</span><span style="line-height: 22.75px; color: rgb(102, 102, 0);">().</span><span style="line-height: 22.75px; color: rgb(0, 0, 0);">setFlags</span><span style="line-height: 22.75px; color: rgb(102, 102, 0);">(</span><span style="line-height: 22.75px; color: rgb(102, 0, 102);">WindowManager</span><span style="line-height: 22.75px; color: rgb(102, 102, 0);">.</span><span style="line-height: 22.75px; color: rgb(102, 0, 102);">LayoutParams</span><span style="line-height: 22.75px; color: rgb(102, 102, 0);">.</span><span style="line-height: 22.75px; color: rgb(0, 0, 0);">FLAG_ALT_FOCUSABLE_IM</span><span style="line-height: 22.75px; color: rgb(102, 102, 0);">,</span><span style="line-height: 22.75px; color: rgb(0, 0, 0);"> <span class="pln"> </span></span><span style="line-height: 22.75px; color: rgb(102, 0, 102);">WindowManager</span><span style="line-height: 22.75px; color: rgb(102, 102, 0);">.</span><span style="line-height: 22.75px; color: rgb(102, 0, 102);">LayoutParams</span><span style="line-height: 22.75px; color: rgb(102, 102, 0);">.</span><span style="line-height: 22.75px; color: rgb(0, 0, 0);">FLAG_ALT_FOCUSABLE_IM</span><span style="line-height: 22.75px; color: rgb(102, 102, 0);">);</span>
这是默认情况下隐藏软键盘的方法,要重新显示软键盘,要执行下面这段代码:
alertDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
AlertDialog.setView()则不会出现以上问题。