Android Studio 基于xml文件用Dialog和Inflate实现点击自定义隐私政策弹窗

前提说明:本人实力水平有限,对于发布的内容可能存在错误或者偏差,请各位大佬不吝赐教!

步骤一:

首先我们需要自定义一个xml文件,并定义占位组件,后续我们可以将一些需要添加的内容加入到占位组件中:

假设我们要做一个隐私政策弹窗,那么我们可以这样定义我们的xml文件:

找到 layout -> new -> XML -> Layout XML File

 然后定义一个名字,这里我定义为 layout_privacy (可能不太规范,开发是时候一定要根据公司需求去定义名称,这样会让我们团队协作更加方便)

 然后我们可以在这个 layout_privacy.xml文件中写入如下前端代码:(这里我们需要一定的基础,比如你已经知道了如何自己写前端代码了)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/dialog_privacy_shape"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <androidx.appcompat.widget.Toolbar
            android:layout_width="56dp"
            android:layout_height="46dp"
            android:layout_gravity="right"
            android:onClick="onClickPrivacyBack"
            app:navigationIcon="@drawable/baseline_cancel_24"
            />
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:orientation="vertical">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="隐私政策"
                        android:textColor="#000"
                        android:textSize="26sp">
                    </TextView>
                    &l
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值