在Android程序中由于界面风格不同,一般会根据项目需求定义相应的对话框样式,废话不多说,先上效果图。
先在activity_main布局文件中,放置一个按钮,用于弹出对话框
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
tools:context=".MainActivity">
<Button
android:id="@+id/showDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="弹出自定义对话框"/>
创建对话框的显示页面custom_dialog.xml显示界面信息
<?xml version="1.0" encoding="utf-8"?><LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tittle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#000"
android:textSize="36sp"
android:visibility="visible"/>
<TextView
android:id="@+id/msg"
android:layout_width="match_parent"
android:layout_height="

本文介绍了如何在Android应用中创建自定义的删除对话框。首先在activity_main布局文件中添加触发对话框的按钮,接着设计custom_dialog.xml文件来定义对话框的显示内容。然后创建CustomDialog类,继承自AlertDialog,并初始化对话框组件及点击事件。最后,在MainActivity中实现自定义对话框的功能。
最低0.47元/天 解锁文章
1386

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



