码迷,mamicode.com
首页 > Windows程序 > 详细

关于AlertDialog.getWindow().setContentView(view)不能弹出输入法

时间:2014-11-11 00:36:37      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:android   style   http   io   color   ar   os   sp   for   

可以阅读官方文档:http://developer.android.com/reference/android/app/Dialog.html

其中有一段:

Note: Activities provide a facility to manage the creation, saving and restoring of dialogs. See onCreateDialog(int)onPrepareDialog(int, Dialog)showDialog(int), anddismissDialog(int). If these methods are used, getOwnerActivity() will return the Activity that managed this dialog.

Often you will want to have a Dialog display on top of the current input method, because there is no reason for it to accept text. You can do this by setting theWindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM window flag (assuming your Dialog takes input focus, as it the default) with the following code:

 getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
         WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
这是默认情况下隐藏软键盘的方法,要重新显示软键盘,要执行下面这段代码:

alertDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

AlertDialog.setView()则不会出现以上问题。
 
另外:为了防止弹出输入法时把后面的背景挤变形,可以在Manifest里添加:

android:windowSoftInputMode="adjustPan|stateHidden"

关于AlertDialog.getWindow().setContentView(view)不能弹出输入法

标签:android   style   http   io   color   ar   os   sp   for   

原文地址:http://www.cnblogs.com/Ringer/p/4088491.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!