我正在将ClickableSpan子类化为我的TextView中的链接自定义文本样式。
private static class LinkSpan extends ClickableSpan {
@Override
public void onClick(View widget) {
// code...
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
ds.setTypeface(Typeface.create(ds.getTypeface(), Typeface.BOLD));
ds.setColor(0xff336699);
}
}
我希望在处于按下状态或用户触摸链接时更改样式。 (比如css中的a:hover
)但我无法找到一种方法来获取updateDrawState
中的当前状态。
有没有办法解决这个问题?如果我无法更改文本样式,我希望至少能够更改背景颜色。
编辑如评论所示,您可以在Change the text color of a single ClickableSpan when pressed without affecting other ClickableSpans in the same TextView找到答案
答案 0 :(得分:9)
为了改变背景颜色,我做了
testTextView.setHighlightColor(Color.BLUE);
TextView上的。
但是有机会改变文字颜色对我来说会更好。