JaydeepW
JaydeepW

Reputation: 3285

StateList working for parent but not for child views

I am using StateList in android UI to show different drawables for different states of the views.

Heres the code. The problem is when I put android:background="@drawable/state_list" on 1st LinearLayout, it works to highlight the states of "pressed" event.

But if I attach the same StateList to 2nd LinearLayout, it does not work.

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingBottom="5dp"
    android:background="@drawable/highlight_states">     // this WORKS!

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal"
        android:background="@drawable/highlight_states">    // this DOES NOT WORK.

        <ImageButton
            android:id="@+id/profile_call_button"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_gravity="center"
            android:background="@color/transparent"
            android:scaleType="fitCenter"
            android:src="@drawable/icon_phone_green" />
   </LinearLayout>
</LinearLayout>

Heres the code of the StateList I am using. highlight_states.xml

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

Upvotes: 0

Views: 102

Answers (1)

Misca
Misca

Reputation: 469

Set on the child LinearLayout

android:duplicateParentState="true"

Upvotes: 1

Related Questions