0

我有一组由 ImageButton、ImageView 和 TextView 组成的视图。
代码如下所示:

 <ImageButton
            android:id="@+id/imagebutton_com"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:background="@drawable/bean_bg" 
            />

        <ImageView 
            android:id="@+id/imageview_arrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/arrow_1"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="20dp"
            />

        <TextView 
            android:id="@+id/textview_wizard_main_button"
            android:text="Soybeans"
            android:layout_toRightOf="@id/imageview_arrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="17sp"
            android:textStyle="bold"
            android:textColor="@color/white"
            android:layout_margin="10dp"
            />

一切都按预期工作,但我想在 Button 获得焦点时更改 TextView 的 textColor。

我尝试编写一个选择器 xml 文件来做同样的事情,但没有任何效果。
有什么建议吗?

4

2 回答 2

1

您需要在代码中执行此操作。在 ImageButton 上使用OnFocusChangeListener来实现这一点。

于 2012-04-23T15:28:05.833 回答
0

Create a folder color under resources and add selector.xml file to that folder

change property of TextView namely

android:textColor = "@color/white"

to

android:textColor = "@color/selector"
于 2012-04-23T15:40:06.417 回答