我正在关注
creating custom buttons的教程.如果我直接将该样式应用于按钮,它可以工作,但是如果我使用android:buttonStyle将样式应用于主题则不起作用.
示例 – 以下是应用了按钮样式的样式xml:
价值观/ styles.xml
<resources>
<style name="MyTheme" parent="android:Theme.Light">
<!-- the button gets styled but is no longer clickable
if i do it like this -->
<item name="android:buttonStyle">@style/ButtonText</item>
</style>
<style name="ButtonText">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#ffffff</item>
<item name="android:background">@drawable/ruddy_orange_button</item>
</style>
</resources>
绘制/ ruddy_orange_button.xml:
<item android:state_pressed="true">
<shape>
<solid android:color="#70c656" />
<stroke android:width="1dp" android:color="#53933f" />
<corners android:radius="3dp" />
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape>
</item>
<item>
<shape>
<gradient android:angle="270" android:endColor="#fd4d4d" android:startColor="#f24b4b" />
<stroke android:width="1dp" android:color="#f04a4a" />
<corners android:radius="4dp" />
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape>
</item>
</selector>
但是,如果我将样式直接应用于按钮,它可以工作:
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@style/ButtonText"
android:text="hello there" />
关于我在这里做错了什么的指示?
我在Android 2.3.3上测试了这个
来源于github.
解决方法
试试这个:
<style name="ButtonText" parent="@android:style/Widget.Button">