自定義佈局顯示dialog

本文展示了一个使用Java实现自定义AlertDialog的过程,包括初始化对话框、设置内容视图及按钮等操作,并给出了相应的XML布局代码。
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"?>
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

贾修行

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值