Android实现不同字体颜色设置不同的点击事件
龙旋
共 3421字,需浏览 7分钟
· 2022-01-13
在需求中我们需要将下面的文字放到一起,并更改不同的颜色进行区分,还需要将用《用户协议》和《隐私政策》添加不同的点击事情,去跳转进行展示不同的说明
首先这是一个弹框,我们需要先去定义它的布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:background="@drawable/bg_white_5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="30dp"
android:text="用户协议和隐私政策"
android:textColor="@color/color_111111"
android:textSize="15sp" />
<TextView
android:id="@+id/tv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:lineSpacingMultiplier="1.3"
android:paddingStart="15dp"
android:paddingTop="14dp"
android:paddingEnd="15dp"
android:paddingBottom="20dp"
android:text=""
android:textColor="@color/color_333333"
android:textSize="13sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#EEEEEE" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_cancel"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="暂不使用"
android:textColor="@color/color_333333"
android:textSize="16sp" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#EEEEEE" />
<TextView
android:id="@+id/tv_sure"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="同意"
android:textColor="@color/colorMain"
android:textSize="16sp" />
LinearLayout>
LinearLayout>
然后我们需要去定义一个条件去判断是否是第一次打开软件,如果是的话弹出我们这个摊款,如果不是的话则不弹出
//第一次打开APP弹出弹框
if (StringUtils.isEmpty(MyApplication.getIsNew())) {
showDialog();
}
接下来就是针对dialog的操作,直接上干货
private void showDialog() {
final Dialog mDialog;
mDialog = new Dialog(this, R.style.Teldialog);
mDialog.setContentView(R.layout.dialog_show);
mDialog.setCanceledOnTouchOutside(false);
mDialog.setCancelable(false);
mDialog.show();
TextView content = mDialog.findViewById(R.id.tv_content);
String str = "请您务必审慎阅读、充分理解“用户协议”和“隐私政策”各条款,包括但不限于:" +
"为了向您提供交易相关基本功能,我们会收集、使用必要的信息。你可阅读" +
"《用户协议》" + "和" +
"《隐私政策》" +
"了解详细信息。如您同意,请点击“同意”接受我们的服务。";
SpannableStringBuilder ssb = new SpannableStringBuilder();
ssb.append(str);
//第一个出现的位置
final int start = str.indexOf("《");
ssb.setSpan(new ClickableSpan() {
public void onClick(View widget) {
//用户服务协议点击事件
Bundle bundle = new Bundle();
bundle.putString("title", "用户协议");
bundle.putInt("showType", 0);
bundle.putString("content", MyApplication.getDataIndex().get("SYSUSER_PROTOL"));
go(WebActivity.class, bundle);
}
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
//设置文件颜色
ds.setColor(getResources().getColor(R.color.colorMain));
// 去掉下划线
ds.setUnderlineText(false);
}
}, start, start + 6, 0);
//最后一个出现的位置
final int end = str.lastIndexOf("《");
ssb.setSpan(new ClickableSpan() {
public void onClick(View widget) {
//隐私协议点击事件
Bundle bundle = new Bundle();
bundle.putString("title", "隐私政策");
bundle.putInt("showType", 0);
bundle.putString("content", MyApplication.getDataIndex().get("SYSUSER_HIDE_PROTOL"));
go(WebActivity.class, bundle);
}
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
//设置文件颜色
ds.setColor(getResources().getColor(R.color.colorMain));
// 去掉下划线
ds.setUnderlineText(false);
}
}, end, end + 6, 0);
content.setMovementMethod(LinkMovementMethod.getInstance());
content.setText(ssb, TextView.BufferType.SPANNABLE);
mDialog.findViewById(R.id.tv_cancel).setOnClickListener(v -> {
mDialog.dismiss();
finish();
});
mDialog.findViewById(R.id.tv_sure).setOnClickListener(v -> {
mDialog.dismiss();
//更改状态,同意下次进入软件则不再弹出弹框
MyApplication.setIsNew("not");
});
}
最后将dialog的样式附上
<style name="Teldialog" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@color/windowTransactionitem>
<item name="android:windowFrame">@nullitem>
<item name="android:windowNoTitle">trueitem>
<item name="android:windowIsFloating">trueitem>
<item name="android:gravity">bottomitem>
<item name="android:windowIsTranslucent">trueitem>
<item name="android:windowCloseOnTouchOutside">trueitem>
<item name="android:windowContentOverlay">@nullitem>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialogitem>
<item name="android:backgroundDimEnabled">trueitem>
style>
评论
【第129期】程序员的新宠:三款终端工具,让你告别Xshell!
概述 WindTerm:跨平台的SSH利器 首先介绍的是WindTerm,这是一款使用C语言开发的跨平台SSH客户端。它不仅完全免费,而且没有商业使用的限制。WindTerm支持SSH v2、Telnet、Raw Tcp等协议,而且性能出色,甚至超过了FinalShell和Electerm。功能
前端微服务
0
上班的时候,有一群摸鱼搭子非常重要...
上班的时候,有一群摸鱼搭子非常重要!一到上班时间,他们就从四面八方涌进群里冒泡...从八卦聊到股市、从职场聊到乌X兰局势,偶尔还会复读、相亲、battle...然后,下午6点钟准时消失不见...所以你要不要加入我们一起摸鱼?我们有北京、上海、深圳、广州、杭州、武汉、成都、南京等8个城市的摸鱼群,还有
产品经理日记
0
周四002 瑞超:同样落寞的境遇——北雪平vs埃尔夫斯堡
上赛季最终排名联赛第9的北雪平本赛季伊始表现不佳,4轮战罢他们仅以1胜1平2负的战绩排在倒数第三,这支历史上曾夺得13次联赛冠军、6次杯赛冠军老牌劲旅,正如英格兰赛场上的一众百年俱乐部,在低谷中不断探索着出路。球队主教练安德烈亚斯·阿尔姆曾是AIK索尔纳及赫根队的主教练,他于今年年初刚刚拿起球队教鞭
产品与体验
0
日本影山优佳最新杂志照,展现充满透明感的美丽
今天的图文分享的是影山优佳的杂志写真。元日向坂46的影山优佳,登上了写真杂志《周刊FLASH》5/7和5/14合并号的封面。影山优佳是日本艺人、女演员、前偶像。身高155厘米。2001年5月8日出生于东京都。2023年7月从组合日向坂46毕业,之后作为演员活跃的影山优佳,在《周刊FLAS
python教程
0
盘点一个使用超级鹰识别验证码并自动登录的案例
点击上方“Python共享之家”,进行关注回复“资源”即可获赠Python学习资料今日鸡汤江上几人在,天涯孤棹还。大家好,我是皮皮。一、前言前几天在Python钻石交流群【静惜】问了一个Python实现识别验证码并自动登录的问题,提问截图如下:验证码的截图如下所示:二、实现过程这里大家激烈的探讨,【
IT共享之家
0
朋友,你也不想一个人孤孤单单的上班吧?
上班的时候,有一群摸鱼搭子非常重要!一到上班时间,他们就从四面八方涌进群里冒泡...从八卦聊到股市、从职场聊到乌X兰局势,偶尔还会复读、相亲、battle...然后,下午6点钟准时消失不见...所以你要不要加入我们一起摸鱼?我们有北京、上海、深圳、广州、杭州、武汉、成都、南京等8个城市的摸鱼群,还有
产品经理日记
0
美团社招一面,比预想的简单。
面试题大全:www.javacn.site面试这件事就很玄学,有时候你觉得他可能很难,但面完之后竟然出奇的顺利,问的问题你都会;有些你觉得这次面试应该很简单,但去了之后就被问懵了,所以面试这件事有很多一部分运气的成分。所以说,在没有 Offer 之前就是多准备、楞怂面,主打一个大力出奇迹。这不,逛牛
Java中文社群
0
Eiten 一个构建投资组合的好帮手
Eiten是Tradytics的一个开源工具包,它实现了各种统计和算法投资策略,如Eigen组合、最小方差组合、最大夏普比率组合和基于遗传算法的组合。Eiten允许你用自己的股票组合建立自己的投资组合。Eiten中自带的严格测试框架使你能够对你的投资组合更有自信。1.准备开始之前,你要确保Pytho
Python实用宝典
0