天天看点

AlertDialog自定义弹出对话框

弹出对话框,显示自定义的布局文件

弹出对话框提示设置密码或登录密码

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为自定义的普通布局文件