user1351659
user1351659

Reputation: 54

ImageButton and TextView different states

I have a set of Views consisting in an ImageButton, an ImageView and a TextView.
The code looks like this:

 <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"
            />

All works as expected, but I want to change the textColor of the TextView when the Button is focused.

I tried writing a selector xml file to do the same, but nothing worked.
Any suggestion?

Upvotes: 0

Views: 272

Answers (2)

Arif Nadeem
Arif Nadeem

Reputation: 8604

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"

Upvotes: 0

waqaslam
waqaslam

Reputation: 68187

You need to do it in code. Use OnFocusChangeListener on your ImageButton to achieve this.

Upvotes: 1

Related Questions