在android studio中尝试在黑暗模式下更改颜色时,ActionBar不会更改颜色

xyhw6mcr  于 2023-03-27  发布在  Android
关注(0)|答案(1)|浏览(301)

我尝试在Android Studio中的应用程序中更改我的动作栏的颜色。我已经将night\colors.xml文件添加到我的值目录中,以便更改night\themes.xml文件中的颜色,并尝试添加新颜色,而不是我的动作栏的黑色颜色。我已经将任何黑色颜色替换为不同的颜色,但动作栏没有更改,只有某些文本更改,这就是它。如何解决此问题?
下面是mynight\themes.xml的代码:

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.TestApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/purple_200</item>
        <item name="colorPrimaryVariant">@color/purple_700</item>
        <item name="colorOnPrimary">@color/black</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_200</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->
    </style>
</resources>

下面是我的nights\colors.xml文件的代码:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="purple_200">#FFBB86FC</color>
    <color name="purple_500">#239090</color>
    <color name="purple_700">#239090</color>
    <color name="teal_200">#FF03DAC5</color>
    <color name="teal_700">#FF018786</color>
    <color name="black">#FF000000</color>
    <color name="white">#FFFFFFFF</color>
    <color name="blue">#239090</color>
    <color name="grey">#242B2E</color>
</resources>

(我在这段代码中顺便把颜色改回了黑色)
这里也是我的themes.xml中的代码,如果它有帮助的话:

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.TestApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/purple_500</item>
        <item name="colorPrimaryVariant">@color/purple_700</item>
        <item name="colorOnPrimary">@color/white</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->
    </style>
</resources>
twh00eeo

twh00eeo1#

你需要把这个加到你的values\themes.xml

<item name="colorSurface">@color/blue_normal</item>
<item name="colorOnSurface">@color/white</item>

确保colorSurfacecolorPrimary相同,colorOnSurfacecolorOnPrimary相同

相关问题