【发布时间】:2012-01-19 15:38:29
【问题描述】:
我有一个 xml 文件,其中有一个选择器,它定义了按钮的不同状态:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/custom_green_button_selected_state" />
<item android:state_enabled="false" android:drawable="@drawable/custom_green_button_disabled_state" />
<item android:drawable="@drawable/custom_green_button_normal_state"/>
</selector>
然后在我的每个可绘制 xml 中,我都有关于按钮外观的信息:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:type="linear" android:gradientRadius="180"
android:startColor="#6b9f41" android:endColor="#598a3d" />
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp" android:topLeftRadius="7dp"
android:topRightRadius="7dp" />
<padding android:left="15dp" android:right="15dp" android:top="10dp"
android:bottom="10dp" />
</shape>
对于我应用程序中的大多数按钮,我只是将第一个 xml 应用为背景,一切正常。对于特定按钮,我想使用相同的 xml,但通过更改可绘制对象的填充使按钮更窄。我想我会尝试在我的代码中创建一个新的 StateListDrawable 并添加每个单独状态的可绘制 xml 的变异,但是,这些可绘制对象显示为 GradientDrawables,这似乎无法让我访问它们的填充属性。有什么想法吗?
【问题讨论】:
标签: android