Reputation: 989
I want to change my TextView link background colour while user pressed on links.
I have search the web and found nothing.
The result I want is like picture below. The text @GeniusVcsh
is pressed and with a light blue background.
Any help would be very appreciate.
Upvotes: 1
Views: 1822
Reputation: 1996
Try use selector
:
First create selector.xml
in res\drawable
like this:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/holo_blue_bright" android:state_pressed="true"/>
</selector>
then add android:background="@drawable/selector"
and android:clickable="true"
in the TextView
:
<TextView
...
android:background="@drawable/selector"
android:clickable="true"/>
Hope it helps.
Upvotes: 2
Reputation: 5797
I have created a class derived from TextView
to handle links and custom colouring of text just recently. To answer your question, use Html.fromHtml
function and pass it with HTML's font tag with a color attribute.
TextView tvRedText;
...
tvRedText.setText(Html.fromHtml("<font color=\"#ff0000\">" + "This is a red text " + "</font>"));
Upvotes: 0