我想在用戶按鏈接時更改我的TextView鏈接背景色。如何更改懸停時的TextView鏈接背景
我有搜索網站,什麼也沒找到。
我想要的結果如下圖所示。文本@GeniusVcsh
被按下並帶有淺藍色背景。
任何幫助將是非常讚賞。
我想在用戶按鏈接時更改我的TextView鏈接背景色。如何更改懸停時的TextView鏈接背景
我有搜索網站,什麼也沒找到。
我想要的結果如下圖所示。文本@GeniusVcsh
被按下並帶有淺藍色背景。
任何幫助將是非常讚賞。
我創建了一個派生自TextView
的類來處理最近文本的鏈接和自定義着色。要回答您的問題,請使用Html.fromHtml
函數,並將其與帶有顏色屬性的HTML字體標記一起傳遞。
TextView tvRedText;
...
tvRedText.setText(Html.fromHtml("<font color=\"#ff0000\">" + "This is a red text " + "</font>"));
嘗試使用selector
:
首先在res\drawable
創建selector.xml
這樣的:
<?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>
然後在TextView
添加android:background="@drawable/selector"
和android:clickable="true"
:
<TextView
...
android:background="@drawable/selector"
android:clickable="true"/>
希望它能幫助秒。