做项目的时候遇到了这样一个问题,搞了很久,在网上看到一篇文章解决了,现转载过来分享如下:


可以阅读官方文档:developer.android.com/reference/android/app/Dialog.html (CSDN不让写这个地址,自己复制进去看吧)
其中有一段:

=======================================================================================

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"

更多相关文章

  1. Android模拟器连接物理键盘
  2. Android中的EditText默认时不弹出软键盘的方法
  3. Android(安卓)失去焦点,关闭弹出的软键盘
  4. android顶部控件被输入法顶上去的解决办法
  5. android软键盘以及输入法影响界面布局的问题
  6. android 中几个常用属性的设置
  7. android监听Key事件
  8. Android避免进入一页面后EditText自动弹出软键盘
  9. Android(安卓)监听键盘弹出关闭

随机推荐

  1. Android学习——uses-sdk标签详解
  2. 如何在Android工程中导入其它工程作为引
  3. Android: Android学习的几点建议
  4. Android(安卓)初始化语言(Android(安卓)in
  5. Android(安卓)onTouchEvent, onClick及on
  6. Android配置蓝牙键值
  7. 在android4.0.4的SDK里裁剪APK,把不需要的
  8. Android(安卓)NDK编程入门笔记
  9. 谈Android手机客户端的适配测试
  10. [置顶] 2016这一年,回顾我们一起走过的"编