Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android xml selector for layouts

Tags:

java

android

xml

I was wanting to know if there is a selector for layouts like there is for drawables.

Example of selector with drawable:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected -->
<item android:drawable="@drawable/tab_library_clicked"
      android:state_selected="true" />
<!-- When not selected -->
<item android:drawable="@drawable/tab_library_not_clicked" />

But is it possible to have something like this (This code below didn't work for me but it should give you an idea of what I am trying to accomplish):

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected -->
<item android:layout="@layout/tab_library_clicked"
      android:state_selected="true" />
<!-- When not selected -->
<item android:layout="@layout/tab_library_not_clicked" />

like image 893
JoeyL Avatar asked Apr 22 '13 08:04

JoeyL


1 Answers

I might be wrong, but I'm pretty sure this doesn't exist.

The most "sophisticated" you'll be able to do with a selector in XML probably is using a drawable layer list to combine several drawables onto one state.

Alternatively you can try using the touch_down and touch_up events to programmatically call setVisibility() on the layouts, but I imagine the performance will be very poor.

like image 96
Budius Avatar answered Sep 28 '22 16:09

Budius