2012-04-23 61 views
0

我有一组由ImageButton,ImageView和TextView组成的视图。
的代码看起来是这样的:ImageButton和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" 
      /> 

所有工作正常,但我想,当按钮被聚焦到改变的TextView的文字颜色。

我试着写一个选择器xml文件来做同样的事,但没有任何工作。
有什么建议吗?

+0

选择器只对运行活动视图。您不能使用它来更改另一个视图的文本颜色。你应该接受@ waqastam的回答 – 2016-06-03 16:25:04

回答

1

您需要在代码中完成。在您的ImageButton上使用OnFocusChangeListener来实现此目的。

0

创建资源下的文件夹的颜色和selector.xml文件添加到该文件夹​​的TextView

变化特性即

android:textColor = "@color/white"

android:textColor = "@color/selector" 
+0

这是行不通的。选择器仅在活动的View上运行。您不能使用它来更改另一个视图的文本颜色 - 如OP所要求的那样。 – 2016-06-03 16:24:09