Set color of TextView span in Android

前端 未结 15 1496
眼角桃花
眼角桃花 2020-11-22 05:54

Is it possible to set the color of just span of text in a TextView?

I would like to do something similar to the Twitter app, in which a part of the text is blue. See

15条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 06:40

    Another way that could be used in some situations is to set the link color in the properties of the view that is taking the Spannable.

    If your Spannable is going to be used in a TextView, for example, you can set the link color in the XML like this:

    
    

    You can also set it in the code with:

    TextView tv = (TextView) findViewById(R.id.myTextView);
    tv.setLinkTextColor(your_color);
    

提交回复
热议问题