S.M_Emamian
S.M_Emamian

Reputation: 17383

RelativeLayout Drawable Selector doesn't work

I would like to change background relativelayout depending on default,focused and pressed states:

        <RelativeLayout 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:focusable="true"
            android:background="@drawable/clickable_layout_items_right_menu"
            >

            <TextView
                android:id="@+id/txt_view_notification_right_menu" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/str_notifications_right_menu"
                android:layout_centerVertical="true"
                android:layout_alignParentRight="true"
                android:layout_marginRight="2dp"
                android:textSize="@dimen/dim_right_menu_items"
                />

            <ImageView 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/left_arrow"
                android:layout_alignParentLeft="true"
                />

        </RelativeLayout>

my clickable_layout_items_right_menu selector :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:state_enabled="false"
          android:drawable="@color/color_default_right_menu" /> <!-- pressed -->
    <item android:state_focused="true"
          android:drawable="@color/color_focused_right_menu" /> <!-- focused -->
    <item android:drawable="@color/color_default_right_menu" /> <!-- default -->
</selector>

colors:

<color name="color_default_right_menu">#33b5e5</color>
<color name="color_focused_right_menu">#45f209</color>
<color name="color_pressed_right_menu">#ffffff</color>

But I have problem, only default state works fine !

Upvotes: 0

Views: 1081

Answers (1)

Dan Harms
Dan Harms

Reputation: 4840

Remove android:state_enabled="false" and replace the pressed drawable with android:drawable="@color/color_pressed_right_menu".

Upvotes: 2

Related Questions