最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實現(xiàn)隱私政策彈窗與鏈接功能

 更新時間:2021年07月12日 16:51:46   作者:Z|Star  
現(xiàn)在幾乎所有的應(yīng)用市場都要求應(yīng)用上架需要用戶協(xié)議/隱私政策,本篇內(nèi)容將介紹如何在APP內(nèi)植入一個隱私政策彈窗與鏈接,對Android隱私政策彈窗實現(xiàn)代碼感興趣的朋友跟隨小編一起看看吧

1.效果展示

先展示效果,看看是不是你需要的。

在這里插入圖片描述
在這里插入圖片描述

2.具體實現(xiàn)

 2.1按鈕美化

在drawable文件夾下新建button_shape.xml

<?xml version="1.0" encoding="utf-8" ?>
<!--相當(dāng)于做了一張圓角的圖片,然后給button作為背景圖片-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <!--設(shè)置背景色-->
    <solid android:color="#F59E27" />
    <!--設(shè)置圓角-->
    <corners android:radius="105dip" />
    <padding
        android:bottom="2dp"
        android:left="33dp"
        android:right="33dp"
        android:top="2dp">
    </padding>
</shape>

2.2彈窗美化

在drawable文件夾下新建dialog_privacy_shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <!-- 填充色 -->
    <solid android:color="#ffffff" />
    <!-- 矩形圓角半徑 -->
    <corners android:radius="10dp" />
</shape>

2.3隱私信息

在assets文件夾下新建privacy.txt,內(nèi)容為彈窗主體信息。

2.4彈窗布局

在layout文件夾下新建一個布局dialog_privacy_show.xml

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/ll_btn_bottom"
            android:layout_marginBottom="15dp"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:id="@+id/tv_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:text="羲和隱私政策"
                android:textColor="#000000"
                android:textSize="18sp" />

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:fadingEdgeLength="50dp"
                android:requiresFadingEdge="horizontal">

                <TextView
                    android:id="@+id/tv_content"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="10dp"
                    android:singleLine="false"
                    android:text=""
                    android:textColor="#000000" />
            </ScrollView>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/ll_btn_bottom"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:gravity="center"

            >
            <Button
                android:id="@+id/btn_agree"
                android:layout_width="130dp"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginRight="15dp"
                android:text="同意"
                android:onClick="onClickAgree"
                android:textColor="#FF0006"
                android:background="@drawable/button_shape"/>
            <Button
                android:id="@+id/btn_disagree"
                android:layout_width="130dp"
                android:layout_marginBottom="2dp"
                android:layout_height="wrap_content"
                android:text="放棄使用"
                android:onClick="onClickDisagree"
                android:textColor="#000000"
                android:background="@drawable/button_shape"/>

        </LinearLayout>
    </RelativeLayout>
</LinearLayout>

效果:

在這里插入圖片描述

2.5彈窗鏈接

新建一個活動yinsi.xml
先寫活動布局

<LinearLayout android:layout_width="match_parent"
    android:layout_height="30dp"
    android:orientation="horizontal"
    android:gravity="center"
    xmlns:android="http://schemas.android.com/apk/res/android">



    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="點擊查看"
        android:textSize="14sp"
        />

    <TextView
        android:id="@+id/tv_xieyi"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onClickPrivacy"
        android:text="隱私政策"
        android:textColor="#0000ff"
        android:textSize="14sp" />

</LinearLayout>

再修改活動的java文件,實現(xiàn)點擊鏈接可以跳出彈窗

package cn.edu.cdut.xihe;
import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

public class yinsi extends AppCompatActivity {
    Dialog dialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yinsi);
    }
    public void onClickAgree(View v)
    {
        dialog.dismiss();
    }
    public void onClickDisagree(View v)
    {
        finish();
    }
    public void onClickPrivacy(View v)
    {
        showPrivacy("privacy.txt");//放在assets目錄下的隱私政策文本文件
    }
    public void showPrivacy(String privacyFileName)
    {
        String str = initAssets(privacyFileName);
        final View inflate = LayoutInflater.from(yinsi.this).inflate(R.layout.dialog_privacy_show, null);
        TextView tv_title = (TextView) inflate.findViewById(R.id.tv_title);
        tv_title.setText("羲和隱私政策");
        TextView tv_content = (TextView) inflate.findViewById(R.id.tv_content);
        tv_content.setText(str);
        dialog = new AlertDialog
                .Builder(yinsi.this)
                .setView(inflate)
                .show();
        // 通過WindowManager獲取
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        final WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
        params.width = dm.widthPixels*4/5;
        params.height = dm.heightPixels*1/2;
        dialog.getWindow().setAttributes(params);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    }
    /**
     * 從assets下的txt文件中讀取數(shù)據(jù)
     */
    public String initAssets(String fileName) {
        String str = null;
        try {
            InputStream inputStream = getAssets().open(fileName);

            str = getString(inputStream);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        return str;
    }
    public static String getString(InputStream inputStream) {
        InputStreamReader inputStreamReader = null;
        try {
            inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }
        BufferedReader reader = new BufferedReader(inputStreamReader);
        StringBuffer sb = new StringBuffer("");
        String line;
        try {
            while ((line = reader.readLine()) != null) {
                sb.append(line);
                sb.append("\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sb.toString();
    }

}

做到這里,基本完成。

3.進(jìn)一步優(yōu)化

1.由于新建的是一個活動,因此該鏈接可以放到其它的布局文件中,用include引入。
2.一般來說,用戶首次啟動才需要彈窗,可以在主頁面的啟動中加入彈窗程序,并加入一個判斷是否首次啟動。
3.這里點擊鏈接是出現(xiàn)彈窗,更多情況是點擊鏈接會跳轉(zhuǎn)到相應(yīng)政策頁面,這里沒做進(jìn)一步編寫,寫一個WebView分裝網(wǎng)頁文件即可。

4.參考資料

本篇內(nèi)容主要參考于博主靈思致遠(yuǎn)Leansmall上傳的資源安卓PrivacyShow隱私彈出框

到此這篇關(guān)于Android:隱私政策彈窗與鏈接的文章就介紹到這了,更多相關(guān)Android隱私政策彈窗內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

祁东县| 六枝特区| 宜丰县| 河津市| 政和县| 宾川县| 阿图什市| 玛曲县| 清涧县| 安远县| 佳木斯市| 澳门| 民勤县| 沙坪坝区| 阿鲁科尔沁旗| 道真| 梓潼县| 桃江县| 麻城市| 武鸣县| 义乌市| 建始县| 彭州市| 古蔺县| 宁陵县| 贵州省| 云浮市| 连州市| 轮台县| 新疆| 靖江市| 五原县| 石景山区| 龙井市| 闽侯县| 登封市| 朝阳市| 康平县| 鄯善县| 慈利县| 哈巴河县|