Change Padding in Selector drawable

android, drawable, padding, selector

Solution

try this

<solid android:color="#ffffff" />

<stroke
    android:width="2dp"
    android:color="@android:color/black" />

<padding
    android:bottom="10dp"
    android:left="10dp"
    android:right="10dp"
    android:top="10dp" />

<corners
    android:bottomLeftRadius="6dp"
    android:bottomRightRadius="6dp"
    android:topLeftRadius="6dp"
    android:topRightRadius="6dp" />

Problem

i am trying to change the padding from a Button in a custom drawable ressource, and reuse this in a selector. Changing the drawable seems not the Problem, but the App always use the highest padding aviable from the different drawables: button_inactive.xml ``` <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle" > <solid android:color="#FF4d681f" /> </shape> </item> <item android:bottom="2dp" android:left="2dp" android:right="2dp" android:top="2dp"> <shape android:shape="rectangle" > <solid android:color="#FFFFFFFF" /> <padding android:bottom="5dp" android:top="5dp" /> </shape> </item> ``` button_active.xml ``` <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle" > <solid android:color="#FF4D681F" /> </shape> </item> <item android:bottom="2dp" android:left="2dp" android:right="2dp" android:top="2dp"> <shape android:shape="rectangle" > <solid android:color="#FF8da32d" /> <padding android:bottom="10dp" android:top="10dp" /> </shape> </item> ``` button_selector.xml ``` <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/button_active"/> <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/button_active"/> <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/button_active"/> <item android:drawable="@drawable/button_inactive"/> ``` The Problem is that my Button uses the 10dp padding in all states, including the "inactive" state. Is there a Solution to get it working only with XML or it is better to make a custom Button programaticly?

Original source

Related problems