这篇文章主要讲解了“Android怎么实现隐私政策弹窗与链接功能”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Android怎么实现隐私政策弹窗与链接功能”吧!
创新互联公司于2013年创立,先为潮州等服务建站,潮州等地企业,进行企业商务咨询服务。为潮州企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
1.效果展示
先展示效果,看看是不是你需要的。


2.具体实现
2.1按钮美化
在drawable文件夹下新建button_shape.xml
2.2弹窗美化
在drawable文件夹下新建dialog_privacy_shape.xml
2.3隐私信息
在assets文件夹下新建privacy.txt,内容为弹窗主体信息。
2.4弹窗布局
在layout文件夹下新建一个布局dialog_privacy_show.xml
效果:

2.5弹窗链接
新建一个活动yinsi.xml
先写活动布局
再修改活动的java文件,实现点击链接可以跳出弹窗
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文件中读取数据
*/
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.进一步优化
1.由于新建的是一个活动,因此该链接可以放到其它的布局文件中,用include引入。
2.一般来说,用户首次启动才需要弹窗,可以在主页面的启动中加入弹窗程序,并加入一个判断是否首次启动。
3.这里点击链接是出现弹窗,更多情况是点击链接会跳转到相应政策页面,这里没做进一步编写,写一个WebView分装网页文件即可。
感谢各位的阅读,以上就是“Android怎么实现隐私政策弹窗与链接功能”的内容了,经过本文的学习后,相信大家对Android怎么实现隐私政策弹窗与链接功能这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!
当前标题:Android怎么实现隐私政策弹窗与链接功能
链接地址:http://www.jxjierui.cn/article/iiddsi.html


咨询
建站咨询
