安卓APP_ 控件(8)—— AlertDialog
摘自:安卓APP_ 控件(8)—— AlertDialog
作者:丶PURSUING
发布时间: 2021-04-02 18:13:20
网址:https://blog.csdn.net/weixin_44742824/article/details/115400659
显示对话框,效果如下图:
具体细节在代码中呈现:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="显示对话框"android:onClick="alert_click"/></LinearLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {private static final String TAG = "zhua";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}//按钮点击直接创建AlertDialogpublic void alert_click(View view) {//etView中需要把布局加载成viewView view_alert = getLayoutInflater().inflate(R.layout.alert_layout, null);//获得构建器AlertDialog.Builder builder = new AlertDialog.Builder(this);//通过构建器进行链式的设置builder.setIcon(R.mipmap.ic_launcher) //添加ICON.setTitle("我是对话框").setMessage("今天天气怎么样")//添加自定义布局:对话框中显示的布局内容.setView(view_alert)//这个参数是一个View,所以需要把布局加载变成view//对话框中的确定按钮.setPositiveButton("确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {Log.e(TAG, "onClick: 点击了确定");}})//对话框中的取消按钮.setNegativeButton("取消", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {Log.e(TAG, "onClick: 点击了取消");}})//对话框中的中间按钮.setNeutralButton("中间", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {Log.e(TAG, "onClick: 点击了中间");}}).create()//创建.show();//显示}
}
创建一个新的布局
alert_layout.xml
<?xml version="1.0" encoding="utf-8"?><!--为了看清楚新的布局在对话框中的大小,设置背景颜色为黄色-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#ffff00"android:orientation="horizontal"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@mipmap/ic_launcher"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="今天天气很好"/></LinearLayout>
安卓APP_ 控件(8)—— AlertDialog相关推荐
- 安卓APP_ 控件(11)webView —— 简单应用:显示网页
摘自:安卓APP_ 控件(11)webView -- 简单应用:显示网页 作者:丶PURSUING 发布时间: 2021-05-11 11:50:52 网址:https://blog.csdn.net ...
- 安卓APP_ 控件(10)—— ListView可上下滑动的列表(重要)与ViewHolder优化
摘自:安卓APP_ 控件(10)-- ListView可上下滑动的列表(重要)与ViewHolder优化 作者:丶PURSUING 发布时间: 2021-04-12 23:28:27 网址:https ...
- 安卓APP_ 控件(9)—— PopupWindow弹窗
摘自:安卓APP_ 控件(9)-- PopupWindow弹窗 作者:丶PURSUING 发布时间: 2021-04-05 14:41:35 网址:https://blog.csdn.net/weix ...
- 安卓APP_ 控件(7)——Toolbar栏目样式
摘自:安卓APP_ 控件(7)--Toolbar栏目样式 作者:丶PURSUING 发布时间: 2021-04-02 15:42:07 网址:https://blog.csdn.net/weixin_ ...
- 安卓APP_ 控件(6)—— Notification通知
摘自:安卓APP_ 控件(6)-- Notification通知 作者:丶PURSUING 发布时间: 2021-04-02 00:30:14 网址:https://blog.csdn.net/wei ...
- 安卓APP_ 控件(5)—— ProgressBar
摘自:安卓APP_ 控件(5)-- ProgressBar 作者:丶PURSUING 发布时间: 2021-03-31 13:03:07 网址:https://blog.csdn.net/weixin ...
- 安卓APP_ 控件(4)—— ImageView
摘自:安卓APP_ 控件(4)-- ImageView 作者:丶PURSUING 发布时间: 2021-03-29 21:52:06 网址:https://blog.csdn.net/weixin_4 ...
- 安卓APP_ 控件(3)—— EditText
摘自:安卓APP_ 控件(3)-- EditText 作者:丶PURSUING 发布时间: 2021-03-29 18:43:40 网址:https://blog.csdn.net/weixin_44 ...
- 安卓APP_ 控件(2)—— Button
摘自:安卓APP_ 控件(2)-- Button 作者:丶PURSUING 发布时间: 2021-03-29 14:20:54 网址:https://blog.csdn.net/weixin_4474 ...
最新文章
- Android官方模拟器root,在Android模拟器上如何获得root权限?
- busybox filesystem httpd php-5.5.31 sqlite3 webserver
- POJ 2229 Sumsets
- Python处理word文件
- 前端学习(3015):vue+element今日头条管理--自定义验证规则
- Java异常的概念和分类
- 详细说说ActionScript中function的call()方法和apply()方法
- 何小鹏:从工程师思维到用户思维,这是互联网造车将带来的变革
- mysql sqrt_详解MySQL中的SQRT函数的使用方法
- oracle 检查链接数,oracle连接数检查
- OpenCV3编程入门(毛星云)读书笔记(一)
- 计算机桌面空白图标如何删除,我的电脑里有一个空白图标怎么删除
- mysql实现停车场管理系统完整代码实现_JAVA实现简单停车场系统代码
- linux系统上搭建静态网站
- Spring+SpringMVC+Mybatis开发
- 大数据开发之在idea中开发第一个hadoop程序
- 【圣诞节限定】教你用Python画圣诞树,做个浪漫的程序员
- 【GitHub】GitHub上值得收藏的100个精选前端项目!
- GSoC 2015 总结
- 推荐一个好玩网站,黑白照片上色、人脸识别都不是问题!
热门文章
- Eclipse预编译的include路径与宏定义
- python 进程编程速成
- 细数家庭安防五大乱象 何时能步入正轨
- CoreAnimation —— CAReplicatorLayer(拷贝图层)
- CentOS系列启动流程和内核原理(5系列,6系列,7系列)
- 偷窃转基因玉米种子引发中美打农业官司
- 关于Linux下的umask
- python之moviepy库的安装与使用
- 嵌入式系统文件系统比较 jffs2, yaffs, cramfs, romfs, ramdisk, ramfs/tmpfs
- 主流开源编解码器Xvid,x264,ffmpeg 性能对比