Android工具栏样式:自定义主题未应用

3

我想自定义工具栏的颜色,但是工具栏的自定义样式更改不起作用。
我使用了appcompat 'com.android.support:appcompat-v7:22.1.1'
在工具栏中,我设置了:

 <android.support.v7.widget.Toolbar
     android:theme="@style/StyleTest" 

(我也尝试使用 app:theme 但是这些都没有生效)
这是我的工具栏样式:

<style name="StyleTest" parent="Theme.AppCompat.NoActionBar">
    <item name="android:textColorPrimary">@color/green</item>
    <item name="actionMenuTextColor">@color/yellow</item>
    <item name="android:textColorSecondary">@color/red</item>
</style>

这种样式不起作用。 但是当我更改应用程序样式项时,工具栏中的样式也会更改(而工具栏具有自己的android:theme值)。 例如,当我更改应用程序样式项“textColorSecondary”时,工具栏中的返回箭头也会更改,但我想在工具栏样式和应用程序样式中使用不同的颜色。 这是应用程序样式:

<!-- Application theme. -->
    <style name="AppTheme" parent="MaterialDrawerTheme.Light.DarkToolbar">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        <!-- colorPrimary is a toolbar background -->
        <item name="colorPrimary">#5EB1F7</item>
        <!-- colorAccent color of pressed widget -->
        <item name="colorAccent">@color/blue_dark</item>
        <item name="actionModeBackground">@color/black_half_transparent</item>
        <item name="android:textColor">@color/black</item>
        <!-- textColorPrimary is a color of the title for Toolbar -->
        <item name="android:textColorPrimary">@color/white</item>
        <!-- colorPrimaryDark is a color for lollipop system bar -->
        <item name="colorPrimaryDark">@color/material_drawer_background</item>
        <!-- android:textColorSecondary is the color of the back arrow and menu
             overflow icon (three vertical dots) -->
        <item name="android:textColorSecondary">@color/blue</item>
    </style>

当我更改应用程序样式项,例如colorPrimary、textColorPrimary或textColorSecondary时,这会应用于工具栏,但工具栏自身的样式被忽略了。 我该如何将自定义样式应用于工具栏?

我有同样的问题,但是是关于TabLayout。 - WojciechKo
2个回答

0
使用 XML 中的 app:theme,并从 StyleTest 的属性中移除 android: 前缀。

正如你所看到的,我尝试了app:theme,但没有任何效果。同时,移除"android:"也没有作用。 - Alex Maddyson

0
我猜你需要这样使用样式:
<android.support.v7.widget.Toolbar
     style="@style/StyleTest" />

小心使用没有 android: 前缀的 style


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接