使用alertdailog来实现用户登录的时候,发现EditText无法打开软件盘,
上原代码
AlertDialog.Builder builder = new AlertDialog.Builder(context);
final AlertDialog dialog = builder.create();
View v = LayoutInflater.from(context).inflate(R.layout.dailog_login, null);
Button regist = (Button) v.findViewById(R.id.dailog_login_btn_regist);
dialog.show();
dialog.getWindow().setContentView(v);
效果图
效果不错,但是不会弹出软件盘面
修改代码
AlertDialog.Builder builder = new AlertDialog.Builder(context);
final AlertDialog dialog = builder.create();
View v = LayoutInflater.from(context).inflate(R.layout.dailog_login, null);
Button regist = (Button) v.findViewById(R.id.dailog_login_btn_regist);
//注意下面这句话
dialog.setView(((Activity)context).getLayoutInflater().inflate(R.layout.dailog_login, null));
dialog.show();
dialog.getWindow().setContentView(v);
效果图
ok,问题解决