工具栏 - 灯光标题和灯光菜单

时间:2014-12-20 13:05:55

标签: android styles android-appcompat

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

以下是截图:

enter image description here

我只想让标题文字颜色为白色。

这是我的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"/>

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

2 个答案:

答案 0 :(得分:16)

将其添加到工具栏元素

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

答案 1 :(得分:3)

您只需要在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"
相关问题