欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

1.效果展示

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

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

2.具體實(shí)現(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文件夾下新建一個(gè)布局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彈窗鏈接

新建一個(gè)活動(dòng)yinsi.xml
先寫活動(dòng)布局

<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="點(diǎn)擊查看"
        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>

再修改活動(dòng)的java文件,實(shí)現(xiàn)點(diǎ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.由于新建的是一個(gè)活動(dòng),因此該鏈接可以放到其它的布局文件中,用include引入。
2.一般來(lái)說,用戶首次啟動(dòng)才需要彈窗,可以在主頁(yè)面的啟動(dòng)中加入彈窗程序,并加入一個(gè)判斷是否首次啟動(dòng)。
3.這里點(diǎn)擊鏈接是出現(xiàn)彈窗,更多情況是點(diǎn)擊鏈接會(huì)跳轉(zhuǎn)到相應(yīng)政策頁(yè)面,這里沒做進(jìn)一步編寫,寫一個(gè)WebView分裝網(wǎng)頁(yè)文件即可。

4.參考資料

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

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

相關(guān)文章

  • Android反編譯程序整理詳解

    Android反編譯程序整理詳解

    很多做安卓開發(fā)的朋友都在尋找好的反編譯軟件和方法,小編給大家整理的很多目前流行的Android反編譯程序,希望能夠給你提供參考。
    2017-11-11
  • android 使用XStream解析xml的實(shí)例

    android 使用XStream解析xml的實(shí)例

    下面小編就為大家分享一篇android 使用XStream解析xml的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧
    2018-01-01
  • Android中AlertDialog用法實(shí)例分析

    Android中AlertDialog用法實(shí)例分析

    這篇文章主要介紹了Android中AlertDialog用法,結(jié)合實(shí)例形式簡(jiǎn)單分析了AlertDialog的基本調(diào)用與功能實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-01-01
  • TextView顯示文本控件兩種方法 TextView顯示link的方法

    TextView顯示文本控件兩種方法 TextView顯示link的方法

    這篇文章主要為大家詳細(xì)介紹了TextView顯示文本控件兩種方法,TextView顯示link的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • Android運(yùn)用BroadcastReceiver實(shí)現(xiàn)強(qiáng)制下線

    Android運(yùn)用BroadcastReceiver實(shí)現(xiàn)強(qiáng)制下線

    本篇文章主要介紹了Android運(yùn)用BroadcastReceiver實(shí)現(xiàn)強(qiáng)制下線,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Flutter進(jìn)階之實(shí)現(xiàn)動(dòng)畫效果(十)

    Flutter進(jìn)階之實(shí)現(xiàn)動(dòng)畫效果(十)

    這篇文章主要為大家詳細(xì)介紹了Flutter進(jìn)階之實(shí)現(xiàn)動(dòng)畫效果的第十篇,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-08-08
  • 使用Jetpack Compose實(shí)現(xiàn)翻轉(zhuǎn)卡片效果流程詳解

    使用Jetpack Compose實(shí)現(xiàn)翻轉(zhuǎn)卡片效果流程詳解

    Jetpack Compose 是一款基于 Kotlin 的聲明式 UI 工具包,可以方便地創(chuàng)建漂亮的用戶界面。使用 Compose 的動(dòng)畫 API 和可繪制 API,可以輕松實(shí)現(xiàn)翻轉(zhuǎn)卡片效果。通過設(shè)置旋轉(zhuǎn)角度和透明度等屬性,可以使卡片沿著 Y 軸翻轉(zhuǎn),并實(shí)現(xiàn)翻頁(yè)效果
    2023-05-05
  • Android實(shí)現(xiàn)表情功能

    Android實(shí)現(xiàn)表情功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)表情功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • android圖片類型之間相互轉(zhuǎn)換實(shí)現(xiàn)代碼

    android圖片類型之間相互轉(zhuǎn)換實(shí)現(xiàn)代碼

    這篇文章主要介紹了android圖片類型之間相互轉(zhuǎn)換的方法,涉及Android實(shí)現(xiàn)各種常用圖片類型及字節(jié)類型的轉(zhuǎn)換技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-10-10
  • android開發(fā)基礎(chǔ)教程—打電話發(fā)短信

    android開發(fā)基礎(chǔ)教程—打電話發(fā)短信

    打電話發(fā)短信的功能已經(jīng)離不開我們的生活了,記下來(lái)介紹打電話發(fā)短信的具體實(shí)現(xiàn)代碼,感興趣的朋友可以了解下
    2013-01-01

最新評(píng)論