网友通过本文主要向大家介绍了钓鱼大师第五季安卓版,安卓点击弹出对话框,微信对话生成器安卓,安卓对话框,安卓开发弹出对话框等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
安卓第五天笔记-对话框,安卓第五天笔记
安卓第五天笔记--对话框
1.对话框
AlerDialog :功能最丰富
PorgressDialog:进度对话框
DatePickerDialog:日期选择对话框
TimePickerDialog:时间选择对话框
2.使用AlerDailog对话框创建对话框
2.1 步骤
2.2 6种 方法创建对话框的内容
setMessage():设置对话框的内容为简单文本
setItems()设置对话框的内容为简单列表
setSingleChoiceItems():设置对话的内容为单选列表项
setMultiChoiceItems():设置对话框内容为多先列表项
setAdapter():设置对话框的内容为自定的列表项
setView():设置对话框的内容为自定义View
3.创建以上6种内容的对话框
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center_horizontal" tools:context="com.itheima.alerdialog.MainActivity"> <!-- 显示一个普通的文本编辑框组件 --> <EditText android:id="@+id/show" android:layout_width="match_parent" android:layout_height="wrap_content" android:editable="false"/> <!-- 定义一个普通的按钮组件 --> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="简单对话框" android:onClick="simple" /> <!-- 定义一个普通的按钮组件 --> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="简单列表项对话框" android:onClick="simpleList" /> <!-- 定义一个普通的按钮组件 --> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="单选列表项对话框" android:onClick="singleChoice" /> <!-- 定义一个普通的按钮组件 --> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="多选列表项对话框" android:onClick="multiChoice" /> <!-- 定义一个普通的按钮组件 --> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="自定义列表项对话框" android:onClick="customList" /> <!-- 定义一个普通的按钮组件 --> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="自定义View对话框" android:onClick="customView" /> </LinearLayout>
array_item.xml
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tv"> </TextView>
login.xml
<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/loginForm" android:layout_width="match_parent" android:layout_height="match_parent"> <TableRow> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="用户名:" android:textSize="10pt"/> <!-- 输入用户名的文本框 --> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请填写登录账号" android:selectAllOnFocus="true"/> </TableRow> <TableRow> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="密码:" android:textSize="10pt"/> <!-- 输入密码的文本框 --> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请填写密码" android:password="true"/> </TableRow> <TableRow> <TextView android:layout_width="match_parent"