可以阅读官方文档: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”