我可以声明一个主题和一个特定的按钮设计:
<style name="MyTheme" parent="android:style/Theme.Black">
<item name="android:buttonStyle">@style/Button.b1</item>
</style>
<style name="Button.b1" parent="android:style/Widget.Button">
<item name="android:textColor">#000000</item>
</style>
问题是这种样式适用于所有按钮。我想声明一个具有自己风格的特定按钮,独立于其他按钮更改每个主题(类似于“保存”按钮)。任何想法?
我尝试了以下方法:
<style name="Button.MyButton" parent="android:style/Widget.Button">
<item name="android:background">@drawable/shape</item>
</style>
<style name ="Button.MyButton.Theme1">
<item name="android:textColor">#000000</item>
</style>
<style name ="Button.MyButton.Theme2">
<item name="android:textColor">#FFFFFF</item>
</style>
<Button
android:id="@+id/save_button"
android:layout_width="0px"
style="@style/Button.MyButton"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/save"/>
现在按钮独立于主题,但它也应该应用我上面声明的样式属性。目前,它仅应用在 MyButton 范围中声明的属性,而不应用 MyButton.Theme1 或 MyButton.Theme2 中声明的属性。
如果你的主题MyTheme
仅用于定义按钮样式,将其移除;还删除parent
按钮的属性:
<style name="Button.b1">
<item name="android:textColor">#000000</item>
</style>
然后在布局中,仅对您需要的按钮使用样式,如下所示:
<Button
android:id="@+id/btn_custom"
style="@style/Button.b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</Button>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)