Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the pop-up window and link function of privacy policy in Android

Shulou Source: shulou.com Published: 2022-06-01 02:38:33 09月11日 Update

This article mainly explains "how to realize the pop-up window and link function of privacy policy in Android". The content in the article is simple and clear, and it is easy to learn and understand. please follow the editor's train of thought to study and learn "how to realize the pop-up window and link function of privacy policy in Android".

1. Effect display

Show the effect first and see if it's what you need.

two。 Concrete realization of 2.1 button beautification

Create a new button_shape.xml under the drawable folder

2.2 Pop-up window beautification

Create a new dialog_privacy_shape.xml under the drawable folder

2.3 Private Information

Create a new privacy.txt under the assets folder, which contains the body information of the pop-up window.

2.4 pop-up window layout

Create a new layout dialog_privacy_show.xml under the layout folder

Effect:

2.5 pop-up links

Create a new activity yinsi.xml

Write the activity layout first

Then modify the active java file so that you can click the link to jump out of the pop-up window.

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") / / Privacy policy text file placed in the assets directory} public void showPrivacy (String privacyFileName) {String str = initAssets (privacyFileName); final View inflate = LayoutInflater.from (yinsi.this) .originate (R.layout.dialog_privacy_show, null); TextView tv_title = (TextView) inflate.findViewById (R.id.tv_title); tv_title.setText (Xi and Privacy Policy) TextView tv_content = (TextView) inflate.findViewById (R.id.tv_content); tv_content.setText (str); dialog = new AlertDialog .Builder (yinsi.this) .setView (inflate) .show (); / / get DisplayMetrics dm = new DisplayMetrics () through WindowManager; 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) Read data from txt file under assets * / 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 (");}} catch (IOException e) {e.printStackTrace ();} return sb.toString ();}} 3. Further optimization

1. Since the new one is an activity, the link can be placed in another layout file and introduced with include.

two。 Generally speaking, users need a pop-up window only when they start for the first time. You can add a pop-up program to the startup of the main page and add a program to determine whether it is started for the first time.

3. Click on the link here is a pop-up window, more often click on the link will jump to the corresponding policy page, there is no further preparation, write a WebView sub-packaged web page file.

Thank you for your reading. the above is the content of "how to achieve the pop-up window and link function of privacy policy in Android". After the study of this article, I believe you have a deeper understanding of how to achieve the pop-up window and link function of privacy policy in Android. The specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Links files policies privacy functions layout folders activities content effects learning information situation more enter one generally speaking subject home page that is ideas Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Huawei macOS OPPO Reno Shulou Tech Info