我正在尝试从自定义可绘制资源中的按钮更改填充,并在选择器中重用它。更改可绘制对象似乎不是问题,但应用程序始终使用不同可绘制对象的最高填充:
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"/>
问题是我的按钮在所有状态下都使用 10dp 填充,包括“非活动”状态。
是否有解决方案让它只与 XML 一起工作,或者以编程方式制作自定义按钮更好?