自定义Dialog弹框和其背景阴影显示

本文介绍了如何创建自定义Dialog,包括编写布局文件、设置圆角边框、创建自定义Dialog类以及实现半透明背景。通过重写函数和监听事件,使全屏弹框能够响应外部点击关闭。
摘要由CSDN通过智能技术生成

昨天研究了一下自定义Dialog的弹框,其实要点都是把自定义好的view用setContentView(view)的方法设置进dialog里,首先我们先看一个简单的自定义Dialog。

一、写布局文件:custom_dialog_layout.xml(这个布局就是一个简单的提示内容,下面有一个确定的按钮,请参看评论中的效果图)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/content_layout"
    android:layout_gravity="center"
    android:gravity="center">

    <LinearLayout
        android:background="@drawable/dialog_content_white_with_radius"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center">
        <TextView
            android:id="@+id/dialog_content_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="info"
            android:textSize="@dimen/size40"
            android:textColor="@color/word_color_444444"
            android:padding="10dp"
            android:gravity="center"/>
        <View
            android:layout_width="match_parent"
            android:layout_height="0.5dp"
            android:background="@color/divide_line"/>
      
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值