Android Theme.MaterialComponents colorPrimary不工作

Android Theme.MaterialComponents colorPrimary不工作,android,material-design,Android,Material Design,我使用的是主题.MaterialComponent,但它不会影响我的actionBar,为什么 style.xml <!-- Base application theme. --> <style name="AppTheme" parent="Theme.MaterialComponents"> <item name="colorPrimary">@color/colorPrimary</item> <

我使用的是
主题.MaterialComponent
,但它不会影响我的actionBar,为什么

style.xml

 <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowBackground">@color/windowBackground</item>
        <item name="android:textColor">@color/white</item>
    </style>
<resources>
    <color name="colorPrimary">#801336</color>
    <color name="colorPrimaryDark">#510a32</color>
    <color name="colorAccent">#ee4540</color>
    <color name="windowBackground">#2d142c</color>

    <color name="white">#FFF</color>
</resources>

@颜色/原色
@颜色/原色暗
@颜色/颜色重音
@颜色/窗口背景
@颜色/白色
colors.xml

 <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowBackground">@color/windowBackground</item>
        <item name="android:textColor">@color/white</item>
    </style>
<resources>
    <color name="colorPrimary">#801336</color>
    <color name="colorPrimaryDark">#510a32</color>
    <color name="colorAccent">#ee4540</color>
    <color name="windowBackground">#2d142c</color>

    <color name="white">#FFF</color>
</resources>

#801336
#510a32
#ee4540
#2d142c
#FFF

仅使用
主题。MaterialComponents
作为应用程序主题的父级,不会像您注意到的那样对
操作栏产生任何影响。您需要使用从基础主题继承的主题之一

  • Theme.MaterialComponents.NoActionBar
    如果您想使用自己的
    工具栏
    作为
    ActionBar
    并具有深色主题(深色背景上的白色文本)
  • Theme.MaterialComponents.Light
    用于运行时生成的带有
    操作栏的灯光主题(灯光背景上的黑色文本)
  • Theme.MaterialComponents.Light.NoActionBar
    对于具有自己的
    工具栏的灯光主题,没有自动生成的
    操作栏
  • Theme.MaterialComponents.Light.DarkActionBar
    用于除深色
    ActionBar
  • Theme.MaterialComponents.DayNight
    主题
  • Theme.MaterialComponents.DayNight.NoActionBar
    用于没有自动生成的
    ActionBar的DayNight主题
  • Theme.MaterialComponents.DayNight.DarkActionBar
    用于带有深色
    ActionBar的DayNight主题
注意:您可以使用任何颜色,无论您选择什么主题。但如果您选择例如
Theme.MaterialComponents.Light.darkaActionBar
并设置

 <item name="colorPrimary">@color/white</item>
@color/white

然后,您的
操作栏
将是白色的,并且-因为您说您有一个黑色的
操作栏
-文本也将是白色的。因此,您需要确保有足够的对比度。

请将Manifest.xml共享为well@0X0nosugar在清单中,
android:theme=“AppTheme”
,活动中没有主题