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

时间:2015-10-05 13:22:37

标签: android xml android-theme

我有一个使用自定义工具栏样式的应用。以前,它正确应用了主题,但在最近更新Android Studio后,它已停止正常工作。

theme.xml的定义如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="OurTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">

        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="android:buttonStyle">@style/ButtonAppTheme</item>
        <item name="android:imageButtonStyle">@style/ImageButtonAppTheme</item>
        <item name="android:listSeparatorTextViewStyle">@style/BlueListSeparatorTextViewStyle</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>

        <!-- colorPrimary is used for the default action bar background -->
        <item name="colorPrimary">@color/action_bar_color</item>

        <!-- colorPrimaryDark is used for the status bar -->
        <!--<item name="colorPrimaryDark">@color/my_awesome_darker_color</item>-->

        <!-- colorAccent is used as the default value for colorControlActivated
             which is used to tint widgets -->
        <item name="colorAccent">@color/btn_accent_color</item>
    </style>

    <!-- Application theme. -->
    <style name="OurTheme" parent="OurTheme.Base">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        <item name="android:listSeparatorTextViewStyle">@style/BlueListSeparatorTextViewStyle</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    </style>


</resources>

我们的styles.xml包含:

<!-- ActionBar styles ThemeOverlay.AppCompat.ActionBar -->
    <style name="MyActionBar" parent="Widget.AppCompat.ActionBar">
        <item name="android:titleTextStyle">@style/MyActionBarTitleText</item>
    </style>

    <!-- ActionBar title text -->
    <style name="MyActionBarTitleText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/actionbar_text</item>
    </style>

actionbar_text在colors.xml中定义:

<color name="actionbar_text">#ffffffff</color>

最后,我们的自定义工具栏布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    app:theme="@style/ThemeOverlay.AppCompat.Dark" />

以前,这很有效,我们的应用在自定义工具栏中有白色文字。它现在在应用程序的任何地方默认为黑色,我发现的唯一可以更改工具栏标题文本颜色的方法(除了在代码中执行)是将工具栏布局更改为:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    app:titleTextAppearance="@style/MyActionBarTitleText"
    app:theme="@style/ThemeOverlay.AppCompat.Dark" />

请注意,现在我特意告诉操作栏使用MyActionBarTitleText样式。

我还尝试通过将“app:theme”更改为:

来明确告诉它在这里使用自定义主题
app:theme="@style/MyActionBar"

但这没有帮助。

我害怕我不知所措。我知道基本主题的作用,因为我可以更改背景颜色,但使用actionBarStyle项只是拒绝工作。

这也影响了我们的一些自定义按钮布局的文本布局和理由,我无法弄清楚它为什么停止工作。有没有人有任何建议?

0 个答案:

没有答案
相关问题