首页 > 解决方案 > 在 21 岁以下的 Android 中使用 ?attr 失败

问题描述

我在我的 Android 应用程序中使用明暗模式。我在values文件夹中做了一个attrs.xml文件。我调整了 attr 值。我在styles.xml 中为夜间和灯光模式创建了2 个样式。所以它适用于 21 以上的 Android,但不适用于 21 以下。我该如何修复它????

attrs.xml

<declare-styleable name="ds">

    <attr name="backact" format="color"/>
    <attr name="toolbar_backact" format="color"/>
    <attr name="textcolor" format="color"/>



</declare-styleable>

样式.xml

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="backact">@color/backact</item>
    <item name="toolbar_backact">@color/toolbar_backact</item>
    <item name="textcolor">@color/textcolor</item>


</style>


<style name="DarkTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="backact">#0a131c</item>
    <item name="toolbar_backact">#19242e</item>
    <item name="textcolor">#FDFDFD</item>

</style>

标签: androidandroid-studioandroid-darkmode

解决方案


推荐阅读