DCloud_Android_DQQ
DCloud_Android_DQQ
  • 发布:2021-07-08 18:05
  • 更新:2022-03-31 19:48
  • 阅读:7147

uni-app 自定义隐私弹窗样式

分类:uni-app

1 前置条件

  1. hx 3.1.23之后版本

  2. 仅支持uni-app

  3. 仅Android

2 功能说明

HX 3.1.23之前,uni-app默认支持了隐私协议弹窗功能,开发者只要根据文档在manifest.json中配置对应的文案,即可使用固定模板的隐私弹窗

相关的操作文档:https://ask.dcloud.net.cn/article/36937

HX 3.1.23之后,应开发者的需求。uni-app 支持自定义隐私弹窗样式。

隐私弹窗的一级布局文件为
dcloud_custom_privacy_dialog_layout.xml
对应的界面:

隐私弹窗的二级布局文件为
dcloud_custom_privacy_second_dialog_layout.xml
对应的界面:

有需要自定义样式的开发者,只要保证关键组件id不变,界面布局可以自由更改。
下面是一个具备基础元素的布局示例。

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

    <!--隐私协议标题-->  
    <TextView  
        android:id="@+id/tv_custom_privacy_title"  
        android:layout_width="match_parent"  
        android:layout_height="wrap_content"  
        android:layout_marginBottom="12dp"  
        android:gravity="center"  
        android:paddingTop="20dp"  
        android:textColor="#000000"  
        android:textSize="16sp"  
        android:textStyle="bold" />  
    <!--隐私协议内容-->  
    <TextView  
        android:id="@+id/tv_privacy_content"  
        android:layout_width="match_parent"  
        android:layout_height="wrap_content"  
        android:paddingLeft="12dp"  
        android:paddingTop="6dp"  
        android:paddingRight="12dp"  
        android:paddingBottom="2dp"  
         <!--这里可以控制协议内容中的超链接样式,包括链接颜色以及是否有下划线-->  
        android:tag="{'linkColor':'#FF00FF','linkLine':false}" />  

    <!--用户按钮-->  
    <LinearLayout  
        android:layout_width="match_parent"  
        android:layout_height="wrap_content"  
        android:paddingLeft="12dp"  
        android:paddingTop="2dp"  
        android:paddingRight="12dp"  
        android:paddingBottom="8dp">  

        <Button  
            android:id="@+id/btn_custom_privacy_cancel"  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:layout_weight="1"  
            android:background="@null"  
            android:paddingLeft="12dp"  
            android:paddingTop="10dp"  
            android:paddingRight="12dp"  
            android:paddingBottom="10dp"  
            android:text="取消"  
            android:textColor="@drawable/dcloud_custom_rich_dialog_button_text_selecter"  
            android:textSize="14sp"  
            android:visibility="gone" />  

        <Button  
            android:id="@+id/btn_custom_privacy_sure"  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:layout_weight="1"  
            android:background="@null"  
            android:paddingLeft="12dp"  
            android:paddingTop="10dp"  
            android:paddingRight="12dp"  
            android:paddingBottom="10dp"  
            android:text="确认"  
            android:textColor="@drawable/dcloud_custom_rich_dialog_button_text_selecter"  
            android:textSize="14sp"  
            android:visibility="gone" />  

    </LinearLayout>  
</LinearLayout>

明确一个基本原则,隐私弹窗的布局文件 完全按照android 布局文件格式标准。
具备Android原生开发能力的人,可以在不修改基本元素组件id的前提下,自由发挥。

将修改后的同名布局文件,以原生插件的方式提交打包,即可完成对隐私弹窗的覆盖。

3 演示操作步骤

第一步配置默认隐私协议文案:

此时的运行效果

第二步 新建一个原生插件

说明文档:https://nativesupport.dcloud.net.cn/NativePlugin/README

在对应的android/res/layout 目录下,添加一二级布局文件
目录结构如下:

第三步 修改隐私协议弹窗样式

这里只简单修改一下超链接样式。如果需要修改其他内容,需要自行查询android xml布局

将修改后的xml布局保存,打包成原生插件

第四步,集成原生插件,云打包验证效果。

提交云端打包后的运行效果:

演示插件

演示插件:
https://ext.dcloud.net.cn/plugin?id=5581

演示项目

https://download.dcloud.net.cn/ASK_RESOURCE/PrivacyDemo.zip

0 关注 分享

要回复文章请先登录注册

愿随风丶飘雪

愿随风丶飘雪

请问如果是离线打包该怎么办呢
2022-03-31 19:48