Can I have a list of layers inside the selector

I have the following drawings

<!-- button_shape.xml --> <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="false"> <shape android:shape="rectangle"> <corners android:radius="3dp"/> <solid android:color="#006600" /> </shape> </item> <item android:state_pressed="true"> <shape android:shape="rectangle"> <corners android:radius="3dp"/> <solid android:color="#003300" /> </shape> </item> </selector> 

and

 <!-- button_shape_shadowed.xml --> <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <corners android:radius="5dp"/> <solid android:color="#D0D0D0"/> </shape> </item> <item> <inset android:drawable="@drawable/button_shape" android:insetBottom="5dp" android:insetLeft="5dp" android:insetRight="5dp" android:insetTop="5dp"> </inset> </item> </layer-list> 

Is there a way to combine them into one? My main problem is that I cannot have a selector inside an inset . Since button_shape.xml not used anywhere, I do not want to create an additional file for no reason.

+9
android
source share
1 answer

Thank you, guys! The following works, although Android Studio complains that the selector not allowed inside the inset .

 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <corners android:radius="5dp"/> <solid android:color="#D0D0D0"/> </shape> </item> <item> <inset android:insetBottom="2dp"> <selector> <item android:state_pressed="false"> <shape android:shape="rectangle"> <corners android:radius="3dp"/> <solid android:color="#006600" /> </shape> </item> <item android:state_pressed="true"> <shape android:shape="rectangle"> <corners android:radius="3dp"/> <solid android:color="#003300" /> </shape> </item> </selector> </inset> </item> </layer-list> 
+16
source share

All Articles