首页 > 解决方案 > 创建从应用程序主题中设置的默认样式扩展的样式

问题描述

我在我的应用程序主题中设置了默认按钮样式,以便将其应用于应用程序中的每个按钮。
除了默认样式外,很少有按钮需要将其文本大写。所以我想要做的是这样的事情
(以下代码片段不起作用,因为我无法设置parent="?attr/materialButtonStyle"):

<style name="capitalizedButton" parent="?attr/materialButtonStyle">
    <item name="android:textAllCaps">true</item>
</style>

是否可以扩展在 theme.xml 中定义的样式?我不想引用我在主题中设置的本地样式,因为以后可能会更改,而是打算使用主题属性访问它。

标签: androidmaterial-designandroid-themematerial-theme

解决方案


您可以直接将样式传递给ButtonXML 中的小部件,例如:

<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="capitalizedButton"/>

希望你能得到答案。如果不是,请解释您的问题。


推荐阅读