Android_AlertDialog创建对话框
来源:互联网 发布:ubuntu 查看cpu核数 编辑:程序博客网 时间:2024/06/06 10:05
AlertDialog的功能很强大,可以生成各种内容的对话框.总的结构包括图表区,标题区,内容区,按钮区
创建AlertDialog对话框的步骤从下面的例子中介绍
AlertDialog的布局文件很简单,仅仅是需要一个Button和TextView,所以不再赘述
具体的需要以下几个步骤:
第一步:创建AlertDialog.Builder对象
AlertDialog.Builder builder=new AlertDialog.Builder(this);
括号中的参数为上下文,一般为MainActivity.this
第二步:设置builder的标题
builder.setTitle("标题内容");
第三步:设置builder的图标
builder.setIcon(R.drawable.a);
注意:drawable是自己创建的文件夹,a图片是自己存进去的,在res中创建
第四步:为builder添加按钮
添加确定按钮:builder.setPositiveButton("确定",onClick监听事件);
添加确定按钮:builder.setPositiveButton("取消",onClick监听事件);
添加监听事件的方法
new anew android.content.DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }
需要注意的是:这个包下的OnClickListener与View 包查下的 OnClickListener发生冲突所以两个不能一起import
需要注意的是builder一定要create和show
builder.create().show();
例子如下个文件
阅读全文
0 0
- Android_AlertDialog创建对话框
- Android_AlertDialog
- Android_AlertDialog
- android_alertDialog
- Android_AlertDialog与PopWindow
- 创建对话框
- 创建对话框
- 创建对话框
- 从头学android_alertDialog的使用
- 创建模块化对话框
- 创建一个对话框
- 创建简单对话框
- 创建非模态对话框
- 创建非模态对话框
- 创建无模式对话框
- 线程中创建对话框
- 创建对话框.
- 创建模式对话框
- RecyclerView
- 字符集编码的简单概述
- HDU 6055 Regular polygon(几何数学)(多校2)
- IDEA + SVN 导入eclipse项目
- spring boot 的项目在idea下报错,错误信息如下:
- Android_AlertDialog创建对话框
- Vue 2.0 的变化(二)之其他重大更改
- HTTP协议--断点续传
- html、htm、shtml、shtm
- 超链接的相对与绝对路径及锚点设置
- leetcode-Longest Substring Without Repeating Characters
- Laravel5.1 组件 Symfony/var-dumper2.7 在php7下的问题
- c++ 下的explicit关键字
- 神一样的CSDN博客排名规则