自定義佈局顯示dialog

来源:互联网 发布:matlab从txt读取数据 编辑:程序博客网 时间:2024/06/10 18:58
JAVA代碼:ffinal AlertDialog mAlertDialog = new Builder(a).create();mAlertDialog.show();// 必须放在getWindow之前,否则会报异常Window mWindow = mAlertDialog.getWindow();mWindow.setContentView(R.layout.my_alertdialog_2);TextView tvTitle = (TextView) mWindow.findViewById(R.id.tv_title);TextView tvContent = (TextView) mWindow.findViewById(R.id.tv_content);Button mBtnLeft = (Button) mWindow.findViewById(R.id.btnLeft);Button mBtnRight = (Button) mWindow.findViewById(R.id.btnRight);tvTitle.setText("温馨提示");tvContent.setText("退出登录后将不能在使用本软件的一切功能,确定退出吗?");mBtnLeft.setText("取消");mBtnLeft.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {mAlertDialog.cancel();// 关闭对话框}});mBtnRight.setText("确定");mBtnRight.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {mAlertDialog.cancel();// 关闭对话框startActivity(new Intent(a.getApplicationContext(),LoginActivity.class));a.finish();}});XML代碼: shape:<?xml version="1.0" encoding="utf-8"?>
0 0