如何更改工具栏选项中文本的颜色



我不小心删除了我的color.xml文件,当我重新构建它时,我无法解决这个问题。工具栏按钮选项中的文本颜色为白底白。以前不是这样的(以前是黑色文本),但我不知道如何修复它。

以下是我的意思:https://i.stack.imgur.com/k79Ba.jpg

这是我的styles.xml文件:

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/accent_color</item>
        <item name="android:textColorPrimary">@color/abc_primary_text_material_dark</item>
        <item name="android:textColorSecondary">@color/abc_primary_text_material_dark</item>

    </style>
    <style name="FabStyle">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_margin">16dp</item>
        <item name="borderWidth">0dp</item>
        <item name="elevation">6dp</item>
        <item name="pressedTranslationZ">12dp</item>
        <item name="rippleColor">@android:color/white</item>
    </style>
    <style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
        <item name="colorAccent">@color/accent_color</item>
    </style>

</resources>

为了更好地衡量我的colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <!--<color name="accent_color">#69F0AE</color>-->
    <color name="dialog_color">#4db6ac</color>
    <color name="accent_color">#FF4081</color>
    <color name="background_light">#fafafa</color>
    <color name="background">#ffffff</color>
    <color name="text_color">#000000</color>
    <color name="score_color">#9e9e9e</color>
</resources>

这是在MainActivity:中初始化的工具栏

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

这是我的activty xml文件中的工具栏:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="@color/colorPrimary"
    android:theme="@style/AppTheme"
    android:elevation="6dp"
    app:popupTheme="@style/AppTheme"
    />

您可以尝试一下,更改工具栏主题:

<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"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:fitsSystemWindows="true"
    android:clipToPadding="false"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize">

将弹出主题添加到工具栏中。

app:popupTheme="@style/ThemeOverlay.AppCompat.Light"

最新更新