Android - How can I create a selector for Layouts (like an ImageButton selector)

mmfloicvsn

New Member
I have an ImageButton and a LinearLayout wrapping that button, like this:\[code\]<LinearLayout android:id="@+id/homeButtonLayout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/p_buttons_background" android:orientation="vertical" > <ImageButton android:id="@+id/homeButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10px" android:background="@drawable/home_icon" android:onClick="goBackToCameraScreen" /> </LinearLayout>\[/code\]I put a background around the ImageButton in the LinearLayout, as you can see above.I want to be able to change that background (that is, the background of the LinearLayout, not the background of the ImageButton) when the user clicks on the ImageButton. I could do that programmatically, but I want to do that via XML. I could easily change the background of the ImageButton by writing a selector, like this:\[code\] <?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/button_pressed" /> <!-- pressed --> <item android:state_focused="true" android:drawable="@drawable/button_focused" /> <!-- focused --> <item android:drawable="@drawable/button_normal" /> <!-- default --></selector>\[/code\]That's EXACTLY what I want, except that I want to change the LinearLayout background, and not the ImageButton background. How can I create a XML selector just like the one above, but that actually changes the background of the LinearLayout instead of the ImageButton background??Thank you in advance!! =)
 
Back
Top