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"?>
自定義佈局顯示dialog
最新推荐文章于 2024-04-28 14:53:58 发布
本文展示了一个使用Java实现自定义AlertDialog的过程,包括初始化对话框、设置内容视图及按钮等操作,并给出了相应的XML布局代码。
549

被折叠的 条评论
为什么被折叠?



