Droidman
Droidman

Reputation: 11608

Clickable layout background

I have a clickable Layout, defined as following:

<RelativeLayout
    android:id="@+id/Test"
    android:layout_width="match_parent"
    android:layout_height="45dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:clickable="true"
    android:orientation="vertical" 
    android:background="@drawable/test_bg"
    >

and there is a selector used to change the background if it was clicked:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:drawable="@drawable/testclicked"
      android:state_selected="true" />

<item android:drawable="@drawable/test" />

</selector>

the problem is it doesn't work.. for buttons that works fine. What am I doing wrong?

Upvotes: 1

Views: 631

Answers (1)

Dalmas
Dalmas

Reputation: 26547

You should use state_pressed instead of state_selected :

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:drawable="@drawable/testclicked"
        android:state_pressed="true" />
    <item
        android:drawable="@drawable/test" />
</selector>

Upvotes: 3

Related Questions