文章转自:http://21jhf.iteye.com/blog/2007375;
如果AlertDialog中有编辑录入框(newMainLayout里面动态创建了EditText控件),show后无法显示输入法
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(modalWindowTitle);
builder.setView(newMainLayout);
builder.setNegativeButton("返回", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
});
AlertDialog ad = builder.create();
ad.show();
//下面两行代码加入后即可弹出输入法
ad.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
ad.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);