setTheme彩色原色不能作为自定义工具栏中的背景吗?

我有一个我刚刚添加的自定义工具栏。

<?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@color/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark">

    </android.support.v7.widget.Toolbar>

请注意,我将背景设置为colorPrimary。

在style.xml中,我有两种风格:

   <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="Yellow" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">#ffff00</item>
        <item name="colorPrimaryDark">#000000</item>
        <item name="colorAccent">#ffff00</item>
    </style>

我的color.xml

<resources>
    <color name="colorPrimary">#000</color>
    <color name="colorPrimaryDark">#fff</color>
    <color name="colorAccent">#000</color>
</resources>

我使用setTheme更改activity中的颜色:

setTheme(colorId);

它可以工作,除了背景颜色始终是黑色,即使我将setTheme设置为黄色。

你知道为什么吗?

转载请注明出处:http://www.hnsdbxf.com/article/20230526/1577996.html