【问题标题】:Toolbar - Light Title and Light menu工具栏 - 灯光标题和灯光菜单
【发布时间】:2014-12-20 13:05:55
【问题描述】:

我目前正在开发一个实现 Appcompat 工具栏的应用程序。 现在我的问题是,如果我选择 Light Actionbar 作为基础,菜单是白色的,标题是黑色的。 我希望两者都是白色的。 如果我更改为深色操作栏作为基础,文本是白色的,但菜单会变暗。

截图如下:

我只希望标题文本颜色为白色。

这是我的styles.xml:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">@color/primary</item>
    <item name="colorAccent">@color/accent</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
</style>


</resources>

这里是toolbar.xml

<?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:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"/>

我希望你能帮助我。 提前致谢!

【问题讨论】:

    标签: android styles android-appcompat


    【解决方案1】:

    将此添加到您的工具栏元素

    <!-- dark toolbar -->
    <item name="android:theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
    <!-- light popup -->
    <item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
    

    【讨论】:

    • 你是我的英雄:D
    【解决方案2】:

    您只需要在您的 style.xml 中添加以下样式以选择您想要的颜色,请根据您的要求更改颜色:

    <style name="MyToolbarStyle" parent="ThemeOverlay.AppCompat.ActionBar">
        <!-- Used to for the title of the Toolbar -->
        <item name="android:textColorPrimary">#fff</item>
        <!-- Used to for the title of the Toolbar when parent is Theme.AppCompat.Light -->
        <item name="android:textColorPrimaryInverse">#fff</item>
        <!-- Used to color the text of the action menu icons -->
        <item name="android:textColorSecondary">#fff</item>
        <!-- Used to color the overflow menu icon -->
        <item name="actionMenuTextColor">#fff</item>
        <!-- Color of the Toolbar -->
        <item name="android:background">#455a64</item>
    </style>
    

    并确保将此属性添加到您的工具栏:

    app:theme="@style/MyToolbarStyle"
    

    【讨论】:

    • 谢谢。我为android:textColorSecondary 设置了灰色(用于箭头、设置等元素)。还将parent 更改为“AppTheme”,然后白色变成了灰色,正如我所愿。
    猜你喜欢
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-11
    • 1970-01-01
    相关资源
    最近更新 更多