I have the following drawables
<!-- 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 merge them into one? My main problem is that I can't have a selector
inside inset
. Since the button_shape.xml
is not being used anywhere else, I don't want to create an extra file for no reason.
Thanks guys! The following does work, even though Android Studio complains that selector
is not allowed inside 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With