Android AlertDialog有EditText无法弹出输入法的解决

android 

如果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);


你可能感兴趣的:(android)