0

您好,我试图在 imageview 中包含图标,但是当开启暗模式时,颜色很暗,而在精简模式下,它显示为白色,我希望两种模式下的颜色都是白色

矢量// 图标

<vector android:height="24dp" android:tint="@color/white"
    android:viewportHeight="24" android:viewportWidth="24"
    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="@color/white" android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>
</vector>

ImageView // 作为背景包含的图标

<ImageView
        android:id="@+id/backArrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="10dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/ic_baseline_arrow_back_24"
        android:contentDescription="@string/todo"
        android:elevation="10dp" />

theme.xml // litemod/正常

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.MyAppNotFinal" parent="Theme.MaterialComponents.DayNight.NoActionBar">
        <!-- Primary brand color. -->
        <item name="colorOnPrimary">@color/black</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">#FFFFFFFF</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
        <item name="colorOnSecondary">@color/lite_grey</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">@color/black</item>
        <!-- Customize your theme here. -->
        <item name="bottomSheetDialogTheme">@style/AppBottomSheetDialogTheme</item>
    </style>
</resources>

theme.xml // 黑暗模式/夜晚

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.MyAppNotFinal" parent="Theme.MaterialComponents.DayNight.NoActionBar">
        <!-- Primary brand color. -->
        <item name="colorOnPrimary">@color/black</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">#FFFFFFFF</item>
        <item name="colorSecondaryVariant">@color/teal_200</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->
        <item name="bottomSheetDialogTheme">@style/AppBottomSheetDialogTheme</item>
    </style>
</resources>

颜色.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="purple_200">#FFBB86FC</color>
    <color name="purple_500">#FF6200EE</color>
    <color name="purple_700">#FF3700B3</color>
    <color name="teal_200">#FF03DAC5</color>
    <color name="teal_700">#FF018786</color>
    <color name="black">#000000</color>
    <color name="white">#FFFFFFFF</color>
    <color name="grey">#181818</color>
    <color name="lite_grey">#e2e2e2</color>
    <color name="dark_red">#bd081c</color>
    <color name="green">#0B5B37</color>
</resources>
4

1 回答 1

1

好的,我的问题得到了答案,实际上我的应用程序已经有深色元素,当我向图像视图或更多元素添加白色背景时,它在我不想要的设备的深色模式中变为深灰色,所以我得到了这个问题的解决方案

步骤1

删除值中的 night/dark theme.xml

第2步

在 normal/light theme.xml 中的值更改

<style name="Theme.MyAppNotFinal" parent="Theme.MaterialComponents.DayNight.NoActionBar">

<style name="Theme.MyAppNotFinal" parent="Theme.MaterialComponents.Light.NoActionBar">

第 3 步

在同一个 theme.xml // 浅色/普通主题

添加这一行

 <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>

风格内

像这样

<style name="Theme.MyAppNotFinal" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
</style>

如果有人仍然有一些问题,这个方法对我有用,请检查下面的问题它有很多答案希望它对你有用

问题

于 2021-07-20T06:41:20.530 回答