tags:

views:

169

answers:

2

The layout xml is as below. I have a RelativeLayout, which contains a TextView. The OnClick listener is set on RelativeLayout. The RelativeLayout has a selector background. What I want is, when user clicks on the RelativeLayout, the background of the RelativeLayout should change, and the color of the text of the TextView should change too. Even though I set color selector for the TextView, only the selector on RelativeLayout works. The color selector on TextView doesn't work. How can I implement change of both RelativeLayout background and text color of TextView when user clicks the layout? Thanks.

<RelativeLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/background_selector"
        android:id="@+id/mylayout"
>
    <TextView android:id="@+id/mytextview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:typeface="sans"
        android:textSize="18sp"
        android:textStyle="bold"
        android:singleLine="true"
        android:ellipsize="end"
        android:textColor="@drawable/color_blue_selector" 
        />
</RelativeLayout>
A: 

Perhaps you could use OnTouchListener and respond on Down and Up events changing the text color

Asahi
This assumes that you'd like the color to be changed while the layout is being clicked
Asahi
Yes, the assumption stands. But this approach is kind of complicated to implement. I just wonder whether Android has a good way to support this feature.
A: 

Isn't it just to

relativeLayout.setBackgroundResource(R.color.brown);
textView.setTextColor(R.color.white);

... having brown and white defined in res/values/color.xml defined as

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="white">#FFFFFF</color>
    <color name="brown">#2E2B27</color>
</resources>
BennySkogberg