Android自定义删除对话框

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值