严格来说这也不算是原创了,因为项目的原因需要在alertDialog根据spinner的选项动态生成控件,其中遇到一个恶心的问题,创建的edittext无法弹出键盘输入,找了很久,终于在stackoverflow里找到了方法。
问题的原因是这样的(我英文不好就不翻译了
):
OK, so after reading a lot, I have figured out why this is a problem, and I do not need to use any workarounds.
The problem seems to be (at least in my case), that since the place where you enter text is hidden initially (or nested or something), AlertDialog is automatically setting the flag WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM (or some combination of that and WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) so that things don't trigger a soft input to show up.
解决的方法就是加入这一句:
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); 或者在show()的时候这样弄:
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);补充一点,这个好像是有版本要求的,具体大家去看stackoverflow的连接吧!
http://stackoverflow.com/questions/9102074/android-edittext-in-dialog-doesnt-pull-up-soft-keyboard
本文介绍了一个在Android开发中遇到的问题——AlertDialog内的EditText无法弹出软键盘进行输入,并提供了解决方案。问题源于EditText初始隐藏或被嵌套导致系统自动设置了特定标志位,阻止软键盘触发。通过清除这些标志位可以解决此问题。
4119

被折叠的 条评论
为什么被折叠?



