Android隐私弹框
【Android隐私弹框】
Android使用隐私弹框
- 编写Android的APP进去点击的用户隐私弹框
-
- 效果图
- java代码
- xml布局界面
- 如何使用
- 本次弹框分享到此结束,喜欢的点个赞,谢谢大家啦
编写Android的APP进去点击的用户隐私弹框 因为现在发布APP现在都需要在发布前生成一个用户隐私弹框让用户点击,所以手写了一个用以使用
效果图
文章图片
java代码
public class PrivateDialog {private static PrivateDialog instace;
public PrivateDialog() {}public static PrivateDialog getInstace() {if (instace == null) {
synchronized (PrivateDialog.class) {
if (instace == null) {
instace = new PrivateDialog();
}
}
}
return instace;
}private String title = "温馨提示";
private String message;
private String sure;
private String cancle;
private Dialog tipDialog;
private float clickTiem = 0;
/**
* desc: 提示隐私协议框
*/
public void showConnectDialog(Context mContext) {
dismiss();
if ((SystemClock.elapsedRealtime() - clickTiem) < 500) {
return;
}
tipDialog = new AlertDialog.Builder(mContext).create();
tipDialog.setCanceledOnTouchOutside(false);
View view = LayoutInflater.from(mContext).inflate(R.layout.activity_private_dialog, null, false);
TextView tvTitle = view.findViewById(R.id.tv_sava_dialog_title);
TextView dialogTxt = view.findViewById(R.id.tv_sava_dialog_message);
TextView tvcancle = view.findViewById(R.id.tv_sava_dialog_cancel);
TextView tvsure = view.findViewById(R.id.tv_sava_dialog_confirg);
SpannableStringBuilder tvProtocol = new SpannableStringBuilder(dialogTxt.getText().toString());
tvProtocol.setSpan(new CliclSpan(mContext,1),27,35,Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
tvProtocol.setSpan(new CliclSpan(mContext,2),36,42,Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
dialogTxt.setText(tvProtocol);
dialogTxt.setMovementMethod(LinkMovementMethod.getInstance());
if (!this.title.isEmpty()) {
tvTitle.setText(this.title);
}
if (!this.message.isEmpty()) {
//tvMsg.setText(this.message);
}
if (!this.cancle.isEmpty()) {
tvcancle.setText(this.cancle);
}
if (!this.sure.isEmpty()) {
tvsure.setText(this.sure);
}view.findViewById(R.id.tv_sava_dialog_cancel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clickTiem = SystemClock.elapsedRealtime();
tipDialog.dismiss();
if (listener != null) {
listener.cancleClick();
}
}
});
tvsure.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tipDialog.dismiss();
if (listener != null) {
listener.sureClick();
}}
});
tipDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_SEARCH)
{
return true;
}
else
{
return false;
//默认返回 false
}
}
});
tipDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
tipDialog.show();
tipDialog.setCancelable(false);
tipDialog.getWindow().setContentView(view);
//tipDialog.getWindow().setWindowAnimations(R.style.DialogBottom);
// 添加动画WindowManager windowManager = (WindowManager)
mContext.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
WindowManager.LayoutParams params = tipDialog.getWindow().getAttributes();
params.width = (int) (display.getWidth() * 0.8);
tipDialog.getWindow().setAttributes(params);
}public void dismiss() {
if (tipDialog != null) {
if (tipDialog.isShowing()) {
tipDialog.dismiss();
}
tipDialog = null;
}
}public interface OnTipItemClickListener {
void cancleClick();
void sureClick();
void userClick();
void termsClick();
}private OnTipItemClickListener listener;
public PrivateDialog setOnTipItemClickListener(OnTipItemClickListener listener) {
this.listener = listener;
return this;
}public PrivateDialog title(String title) {
this.title = title;
return this;
}public PrivateDialog message(String message) {
this.message = message;
return this;
}public PrivateDialog sure(String sure) {
this.sure = sure;
return this;
}public PrivateDialog cancle(String cancle) {
this.cancle = cancle;
return this;
}public void create(Context mContext) {
showConnectDialog(mContext);
}
class CliclSpan extends ClickableSpan{
Context mContext;
Integer mNum;
public CliclSpan() {
super();
}
public CliclSpan(Context context,Integer num) {
mContext = context;
mNum = num;
}
@Override
public void onClick(@NonNull View widget) {
if (listener != null) {
if(mNum == 1){
listener.userClick();
}else {
listener.termsClick();
}
}
}@Override
public void updateDrawState(@NonNull TextPaint ds) {
ds.setColor(ContextCompat.getColor(mContext,R.color.red));
ds.setUnderlineText(false);
}
}}
xml布局界面 xml文件名:activity_private_dialog
如何使用 服务协议与隐私政策的Activity我就不贴出来了,有需要可以找我要
PrivateDialog.getInstace().message("").sure("同意").cancle("退出应用")
.setOnTipItemClickListener(new PrivateDialog.OnTipItemClickListener() {
@Override
public void cancleClick() {
finishAffinity();
}@Override
public void sureClick() {
//进入app
}@Override
public void userClick() {
//跳转至用户服务协议
toActivity(ProtocolActivity.class);
}@Override
public void termsClick() {![在这里插入图片描述](https://img-blog.csdnimg.cn/23138f9cd70548c2b8eb36547a10fc98.jpg?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5pep5pma6YGH6KeB5L2g,size_8,color_FFFFFF,t_70,g_se,x_16#pic_center)//跳转至隐私政策
toActivity(TermActivity.class);
}
}).create(this);
本次弹框分享到此结束,喜欢的点个赞,谢谢大家啦
推荐阅读
- android第三方框架(五)ButterKnife
- Android中的AES加密-下
- 带有Hilt的Android上的依赖注入
- android|android studio中ndk的使用
- Android事件传递源码分析
- RxJava|RxJava 在Android项目中的使用(一)
- Android7.0|Android7.0 第三方应用无法访问私有库
- 深入理解|深入理解 Android 9.0 Crash 机制(二)
- android防止连续点击的简单实现(kotlin)
- Android|Android install 多个设备时指定设备