简体   繁体   English

如何修复设备的暗模式和精简模式下的图像视图图标颜色变化

[英]how to fix image view icon color changes in dark mode and lite mode of the device

Hello im trying to include icons in imageview but when the dark mode is on the color is dark and when on lite mode its shows in white , i want color to be white in both modes你好,我试图在 imageview 中包含图标,但是当暗模式处于暗模式时,颜色是暗的,而在精简模式时,它显示为白色,我希望两种模式下的颜色都为白色

vector // icon矢量// 图标

<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 // icon included as background 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" />

themes.xml // litemod/normal的themes.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>

themes.xml // dark mod/night themes.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>

colors.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>

Ok i got an answer to my question, acttualy my app already has dark elements and when i add a white background to an imageview or some more elements but it changes to dark grey in the dark mod of the device which i dont want ,so i got an solution to this issue好的,我得到了我的问题的答案,实际上我的应用程序已经有深色元素,当我向图像视图或更多元素添加白色背景时,但它在我不想要的设备的深色模式中变为深灰色,所以我得到了这个问题的解决方案

Step 1第1步

Delete the night/dark theme.xml in the values删除值中的 night/dark theme.xml

Step 2第2步

In the normal/light theme.xml in the values change the在 normal/light theme.xml 中的值更改

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

to

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

Step 3第 3 步

In the same theme.xml // light/normal theme在同一个theme.xml // 浅色/普通主题

add this line添加这一行

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

inside the style在风格里面

like this像这样

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

this method worked for me if anyone still have some issues please check the bellow question it has many answers hope it will work for you这个方法对我有用,如果有人还有问题,请检查下面的问题,它有很多答案希望它对你有用

Question 问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为暗模式设置颜色变体? - How to set color variants for dark mode? Android Q暗模式将可绘制形式的颜色从白色变为灰色 - Android Q dark mode changes color of drawable form white to gray 如果我的手机处于浅色或深色模式,如何制作带有文本和背景颜色的 Android 启动画面? - How can I make an Android splash screen with text & background color that changes if my phone is in light or dark mode? 即使在正常模式下,如何在暗模式下使用可绘制的图像? - how to use image in dark mode drawable even in normal mode? Android:暗模式下的颜色反转 - Android: inverted color on dark mode 深色模式下颜色反转的通知 - Notification with inverted color with dark mode 暗模式干扰背景颜色 - dark mode interfering with background color Xamarin 应用程序在启用暗模式的 Android 设备上自动切换到暗模式 - Xamarin app automatically switching to dark mode on Android device with dark mode on 如何为 Android 10 和 11 的整个设备设置暗模式? - How to set Dark mode for the whole device for Android 10 and 11? Android自动-暗模式下的Google Play拒绝-如何解决? - Android auto - Google play rejection for Dark mode - How to fix?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM