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>
评论
React Playground 实现原理揭秘
大家应该都用过在线写代码的工具,比如 vue 的 playground:左边写代码,右边实时预览。右边还可以看到编译后的代码:这是一个纯前端项目。类似的,也有 React Playground。那它是怎么实现的呢?我们自己能实现一个么?可以的,今天我们来分析下实现思路。首先是编译:编译用的
全栈前端精选
0
在GPU上加速RWKV6模型的Linear Attention计算
精简版:经过一些profile发现flash-linear-attention中的rwkv6 linear attention算子的表现比RWKV-CUDA中的实现性能还要更好,然后也看到了继续优化triton版本kernel的线索。接着还分析了一下rwkv6 cuda kernel的几次开发迭代以
GiantPandaCV
0
早上面试了一个应届生,本来觉得能力很好,快结束时问了一句:现在的工作是不是理想工作?结果他说上班就是为了挣钱,他的理想就是不上班
某老板发帖吐槽:早上面试了一个应届生,本来觉得能力很好准备收了。最后快结束的时候随口问了一句:现在的工作是不是他理想的工作?结果他的回答是:”我上班就是为了挣钱。不想谈理想,我的理想就是不上班!“这样的人还敢不敢收?有人直言:没懂,他说的哪点不对?确实很真实,谁上班不是为了挣钱呢?谁的理想又是上班呢
TTTEED
0
刚刚!ChatGPT绘图:新增一个令人惊喜的功能!
你好,我是郭震ChatGPT绘图刚刚增加一个新功能,支持在生成图中进行再编辑,这篇文章我来详细总结下这个功能。1 初步使用按照正常提问,绘制小猫和草坪。过一会,它会生成这样一幅图片:接下来,点击这张图片,会弹出这个窗口,右上角有三个按钮,第一个按钮是select,也就是选择图片中的某个区域,支持选择
Python与算法社区
0
今天我去美国学校餐厅吃的午饭,看看我吃了啥
你好,我是郭震最近分享了几篇AI技术相关的文章,还没看过的可查看哦:一文总结:AI大模型之LangChain基础用法教程来了!3分钟教你搭建:AI大模型前端界面一文总结Python绘制的10种热力图太赞了!我无意间发现的一本AI大模型PDF,免费下载!打造本地ChatGPT,部署LlaMA3最简单的
Python与算法社区
1
三个优秀的PyTorch实现语义分割框架
点击上方“小白学视觉”,选择加"星标"或“置顶”重磅干货,第一时间送达转自 | 机器学习AI算法工程使用的VOC数据集链接开放在文章中,预训练模型已上传Github,环境我使用Colab pro,大家下载模型做预测即可。代码链接: https://github.com/lixiang007
小白学视觉
0
如何看待稚晖君的时间管理水平?
点击上方“小白学视觉”,选择加"星标"或“置顶”重磅干货,第一时间送达计算机视觉life整理原文链接:https://www.zhihu.com/question/491456524/answer/2183081310稚晖君究竟是如何安排业余时间去做这么多高水平的项目?而且每个项目的用时也很少,普通
小白学视觉
2
如何画出漂亮的神经网络图?神经网络可视化工具集锦搜集
点击上方“小白学视觉”,选择加"星标"或“置顶”重磅干货,第一时间送达1. draw_convnet一个用于画卷积神经网络的Python脚本https://github.com/gwding/draw_convnet2. NNSVGhttp://alexlenail.me/NN-SVG/LeNet.
小白学视觉
0