TextView的ClickableSpan造型为pressed状态 [英] TextView ClickableSpan styling for pressed state

查看:335
本文介绍了TextView的ClickableSpan造型为pressed状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承ClickableSpan自定义文本样式在我TextView的链接。

I am subclassing ClickableSpan to customize the text style for links in my 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);
    }
}

我要改变风格,当它在一个pressed状态,或者用户触摸的链接。 (如 A:悬停在CSS),但我不能想出一个办法让 updateDrawState 当前状态。

I want to change the style when it's in a pressed state, or a user touches the link. (like a:hover in css) but I can't figure out a way to get the current state in updateDrawState.

有什么办法来处理呢?如果我不能改变文本的风格,我希望能够改变背景颜色至少。

Is there any way to handle this? If I can't change text style, I want to be able to change the background color at least.

修改作为指向一个注释,你可以找到在<一个答案href="http://stackoverflow.com/questions/20856105/change-the-text-color-of-a-single-clickablespan-when-$p$pssed-without-affecting-o/20905824#20905824">Change当pressed不会影响同一TextView中其他ClickableSpans单ClickableSpan的文本颜色

EDIT as pointed by a comment, you can find the answer at Change the text color of a single ClickableSpan when pressed without affecting other ClickableSpans in the same TextView

推荐答案

有关更改背景颜色我做了

For changing background color I did

testTextView.setHighlightColor(Color.BLUE);

在TextView的。

on the TextView.

但有机会改变文字颜色将是更好的我。

But having the chance to change the text color would be better to me.

这篇关于TextView的ClickableSpan造型为pressed状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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