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

文章转自: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);

绳锯木断,水滴石穿。海纳百川,积少成多。一分耕耘,一份收获。
原文地址:https://www.cnblogs.com/tittles0k/p/5616362.html