3

我想要一个可点击的 TextView,它可以改变颜色并保持它,它将以前更改的文本更改回默认颜色。当然,我希望在“检查”每个 TextView 时更改某些状态。基本上是一个像 RadioButton 或 RadioButton 减去按钮的 TextView。

起初我试图从 TextView 的角度来。但似乎使用 RadioButtons 并添加文本行为更容易,因为 RadioButtons 无论如何都扩展了 TextView。

所以我将此颜色资源应用于每个 RadioButton:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:color="#0000ff" />
<item android:state_focused="true" android:state_pressed="true" android:color="#0000ff" />
<item android:state_focused="false" android:state_pressed="true" android:color="#0000ff" />
<item android:state_checked="true" android:color="#0000ff" />
<item android:color="#ff00ff00" />
</selector>

这让我得到了我想要的文本行为。现在我只需要一种方法来隐藏 RadioButton 本身。理想情况下,这将是 XML,因此我可以将样式应用于各种 RadioButton,但我不会对 RadioButton 扩展嗤之以鼻。

那么,有人知道如何隐藏 RadioButton 按钮本身吗?

4

1 回答 1

7

你应该使用CheckedTextView. 它支持checked状态。

或者

您可以使用RadioButton并将其按钮设置为null

<RadioButton
    android:id="@+id/button"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/selector"
    android:button="@null"
    android:paddingLeft="0dip"/>
于 2013-01-08T19:51:22.740 回答