自定义主题无法在按钮中应用

时间:2016-10-26 03:55:45

标签: android button themes

这是我的自定义风格:

<style name="ButtonTheme" parent="android:Widget.Button">
    <item name="colorButtonNormal">#00c4a9</item>
    <item name="android:textColor">#ffffff</item>
    <item name="android:textSize">@dimen/user_button_size</item>
</style>

这是我的按钮布局:

<Button
    android:id="@+id/bt_exchange"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginLeft="32dp"
    android:layout_marginRight="32dp"
    android:layout_marginTop="@dimen/normal_margin_16"
    android:theme="@style/ButtonTheme"
    android:gravity="center"
    android:text="@string/integral_exchange_goods" />

结果如下:Result

但主题无法应用于按钮。为什么呢?
非常感谢。

enter image description here

4 个答案:

答案 0 :(得分:0)

尝试使用,

style="@style/ButtonTheme"

答案 1 :(得分:0)

确保您的Activity扩展AppCompatActivity并使用appcompat主题

答案 2 :(得分:0)

以下链接描述了为什么主题不适用于按钮。 https://code.google.com/p/android/issues/detail?id=191980

另请参阅以下内容为按钮添加自定义主题: http://manuel-ohlendorf.de/blog/2015/09/03/material-design-buttons-with-appcompat/

答案 3 :(得分:0)

更改您的样式父级,

parent="android:Widget.Button"

要,

parent="Base.Widget.AppCompat.Button"

还要确保使用AppCompat主题。