我可以更改clickablespan的外观和感觉 [英] can I change the look and feel of the clickablespan

查看:250
本文介绍了我可以更改clickablespan的外观和感觉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在段落文字中嵌入可点击的文字,clickablespan才能做到。但是,而不是使用默认的焦点/按/未聚焦的风格,我可以改变这些风格吗?像焦点时,背景颜色是蓝色,文本颜色是白色,当不聚焦时,背景颜色是白色,文本颜色是蓝色。

I have to embed a clickable text in a paragraph text, clickablespan can do it. But instead of using the default focus/press/unfocus style, can I change those style ? Like when focus, the background color is blue, text color is white, when unfocus, the background color is white, text color is blue.

推荐答案

这里是示例

bottomMsg = (TextView) findViewById(R.id.bottom_msg);
int start = bottomMsg.getText().toString().indexOf(terms);
MovementMethod movementMethod = LinkMovementMethod.getInstance();
bottomMsg.setMovementMethod(movementMethod);

Spannable text = (Spannable) bottomMsg.getText();
//TermAndConditions is a clickableSpan.
text.setSpan(new TermAndConditions(), start, start + terms.length(), Spannable.SPAN_POINT_MARK);
text.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.customYellowColor)), start, start + terms.length(), 0);

重点是,颜色跨度在可点击跨度之后。否则,颜色不变。

The point is, color-span is after the clickable-span. otherwise, the color not changed.

这篇关于我可以更改clickablespan的外观和感觉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆