如何配置一个简易密码弹出框
public void showAlertDialog() {
LayoutInflater inflater = LayoutInflater.from(getActivity());
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.area_dialog_info, null);
// 对话框
final Dialog dialog = new Dialog(getActivity());
// dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setTitle("请输入密码");//设置标题头
dialog.show();//显示Dialog
dialog.setContentView(layout);//加载布局文件
dialog.setCancelable(false);//设置非Dialog界面不可点,手机按键不可点
final EditText mETPassWord = (EditText) layout.findViewById(R.id.et_dialog_confirmphoneguardpswd);
// 取消按钮
Button btnCancel = (Button) layout.findViewById(R.id.btn_dialog_cancel_confirmphoneguardpswd);
btnCancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();//关闭Dialog
}
});
// 确定按钮
Button btnOK = (Button) layout.findViewById(R.id.btn_dialog_resolve_confirmphoneguardpswd);
btnOK.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(mETPassWord.getText().toString().equals("12345")){
dialog.dismiss();
}else if(mETPassWord.getText().toString().equals("")){
ToastUtil.showToast(getActivity(), "请输入密码", Toast.LENGTH_SHORT);
}else{
ToastUtil.showToast(getActivity(), "密码错误", Toast.LENGTH_SHORT);
}
}
});
}