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

时间:2015-05-17 10:59:02

标签: android styles toolbar material-design

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

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

(我也尝试应用:主题但这些也没有影响)
这是我的工具栏样式:

<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中具有自己的样式:主题值)。 例如,当我更改应用程序样式项&#34; textColorSecondary&#34;这也改变了工具栏中的后退箭头,但我想在工具栏样式和应用程序样式中使用不同的颜色。 这是应用程序风格:

<!-- 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>

当我更改app风格的项目时,例如colorPrimary或​​textColorPrimary或​​textColorSecondary这适用于工具栏,但工具栏自己的样式被忽略。 我如何将自定义样式应用于工具栏?

2 个答案:

答案 0 :(得分:1)

在xml中使用app:theme并从StyleTest的属性中删除android:前缀。

答案 1 :(得分:0)

我想你需要以这种方式使用风格:

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

提示style没有android:前缀。

相关问题