Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android主题属性在浅色和深色之间部分切换_Android_Material Design_Android Theme - Fatal编程技术网

Android主题属性在浅色和深色之间部分切换

Android主题属性在浅色和深色之间部分切换,android,material-design,android-theme,Android,Material Design,Android Theme,我正在为我的应用程序构建一个明暗主题。我想为应用程序中的所有按钮使用自定义形状。但是在主题之间切换时,colorAccent属性不会被切换为按钮背景色 在灯光模式下,colorAccent为橙色,并显示橙色 但在暗模式下,colorAccent为紫色,但仍显示橙色 <resources> <!--Top level DayNight theme to be used in AndroidManifest.xml--> <style name="MyC

我正在为我的应用程序构建一个明暗主题。我想为应用程序中的所有按钮使用自定义形状。但是在主题之间切换时,
colorAccent
属性不会被切换为按钮背景色

在灯光模式下,
colorAccent
橙色,并显示橙色

但在暗模式下,
colorAccent
紫色,但仍显示橙色

<resources>
   <!--Top level DayNight theme to be used in AndroidManifest.xml-->
    <style name="MyCustomTheme" parent="Base.MyCustomTheme"/>

    <style name="MyCustomTheme.System.Defaults" parent="Theme.AppCompat.DayNight.DarkActionBar">
        <item name="android:fontFamily">@font/driver_font_family</item>
    </style>


    <style name="Base.MyCustomTheme" parent="MyCustomTheme.System.Defaults">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowBackground">@color/OffWhite</item>

        <!--Component styles-->
        <item name="buttonStyle">@style/MyCustomTheme.Button</item>
    </style>

</resources>
<resources>
    <style name="MyCustomTheme" parent="Base.MyCustomTheme">
        <item name="colorPrimary">@color/Green</item>
        <item name="colorPrimaryDark">@color/Red</item>
        <item name="colorAccent">@color/Purple</item>
        <item name="android:windowBackground">@color/BlackDark</item>
    </style>
</resources>

我知道交换是有效的,因为我可以改变其他颜色,然后它们被采用。这只是按钮的形状

我确信它与形状文件中的
有关

有人能看出我做错了什么吗

轻主题

<resources>
   <!--Top level DayNight theme to be used in AndroidManifest.xml-->
    <style name="MyCustomTheme" parent="Base.MyCustomTheme"/>

    <style name="MyCustomTheme.System.Defaults" parent="Theme.AppCompat.DayNight.DarkActionBar">
        <item name="android:fontFamily">@font/driver_font_family</item>
    </style>


    <style name="Base.MyCustomTheme" parent="MyCustomTheme.System.Defaults">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowBackground">@color/OffWhite</item>

        <!--Component styles-->
        <item name="buttonStyle">@style/MyCustomTheme.Button</item>
    </style>

</resources>
<resources>
    <style name="MyCustomTheme" parent="Base.MyCustomTheme">
        <item name="colorPrimary">@color/Green</item>
        <item name="colorPrimaryDark">@color/Red</item>
        <item name="colorAccent">@color/Purple</item>
        <item name="android:windowBackground">@color/BlackDark</item>
    </style>
</resources>

@字体/驱动程序\u字体\u系列
@颜色/原色
@颜色/原色暗
@颜色/颜色重音
@彩色/灰白色
@style/MyCustomTheme.Button
夜间主题

<resources>
   <!--Top level DayNight theme to be used in AndroidManifest.xml-->
    <style name="MyCustomTheme" parent="Base.MyCustomTheme"/>

    <style name="MyCustomTheme.System.Defaults" parent="Theme.AppCompat.DayNight.DarkActionBar">
        <item name="android:fontFamily">@font/driver_font_family</item>
    </style>


    <style name="Base.MyCustomTheme" parent="MyCustomTheme.System.Defaults">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowBackground">@color/OffWhite</item>

        <!--Component styles-->
        <item name="buttonStyle">@style/MyCustomTheme.Button</item>
    </style>

</resources>
<resources>
    <style name="MyCustomTheme" parent="Base.MyCustomTheme">
        <item name="colorPrimary">@color/Green</item>
        <item name="colorPrimaryDark">@color/Red</item>
        <item name="colorAccent">@color/Purple</item>
        <item name="android:windowBackground">@color/BlackDark</item>
    </style>
</resources>

@颜色/绿色
@颜色/红色
@颜色/紫色
@颜色/黑/暗
圆角.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners  android:radius="10dp" />
    <padding  android:padding="0dp"/>
    <solid android:color="@color/colorAccent" />
</shape>
<resources>
    <!--Leaving these here since they are refrenced by the system and other components-->
    <color name="colorPrimary">@color/NavyBlue</color>
    <color name="colorPrimaryDark">@color/NavyBlueDark</color>
    <color name="colorAccent">@color/Orange</color>

    <color name="Red">#E84E3C</color>
    <color name="Purple">#745EC4</color>
    <color name="Green">#2FCC70</color>
    <color name="NavyBlue">#34495E</color>
    <color name="NavyBlueDark">#2B3D4F</color>
    <color name="BlueDark">#394D82</color>    
    <color name="OffWhite">#EDF1F2</color>
    <color name="BlackDark">#262626</color>
</resources>

colors.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners  android:radius="10dp" />
    <padding  android:padding="0dp"/>
    <solid android:color="@color/colorAccent" />
</shape>
<resources>
    <!--Leaving these here since they are refrenced by the system and other components-->
    <color name="colorPrimary">@color/NavyBlue</color>
    <color name="colorPrimaryDark">@color/NavyBlueDark</color>
    <color name="colorAccent">@color/Orange</color>

    <color name="Red">#E84E3C</color>
    <color name="Purple">#745EC4</color>
    <color name="Green">#2FCC70</color>
    <color name="NavyBlue">#34495E</color>
    <color name="NavyBlueDark">#2B3D4F</color>
    <color name="BlueDark">#394D82</color>    
    <color name="OffWhite">#EDF1F2</color>
    <color name="BlackDark">#262626</color>
</resources>

@颜色/蓝色
@颜色/导航蓝深
@颜色/橙色
#E84E3C
#745EC4
#2FCC70
#34495E
#2B3D4F
#394D82
#EDF1F2
#262626
问题在于:

<solid android:color="@color/colorAccent" />

哇!我真不敢相信我错过了。非常感谢。当时间限制解除时,我将接受答案。