彈出對話框,顯示自定義的布局檔案
彈出對話框提示設定密碼或登入密碼
private void showSetPasswordDialod(){
View dialogView=mInflater.inflate(R.layout.protect_first_dialog, null);
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("設定防盜密碼");
builder.setView(dialogView);
//可通過加載布局的方式擷取到布局檔案中的元件,并進行相應的業務邏輯處理
password=(EditText) dialogView.findViewById(R.id.protect_first_password1);
repassword=(EditText) dialogView.findViewById(R.id.protect_first_password2);
confirm=(Button) dialogView.findViewById(R.id.protect_password_confirm);
cancle=(Button) dialogView.findViewById(R.id.protect_password_cancle);
final AlertDialog dialog=builder.create();
dialog.show();
confirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getBaseContext(), password.getText().toString(), 0).show();
}
});
cancle.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
ProtectedPhoneActivity.this.finish();
}
});
}
protect_first_dialog.xml為自定義的普通布局檔案