前提说明:本人实力水平有限,对于发布的内容可能存在错误或者偏差,请各位大佬不吝赐教!
步骤一:
首先我们需要自定义一个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