如何修复设备的暗模式和精简模式下的图像视图图标颜色变化
How to fix image view icon color changes in dark mode and lite mode of the device
我想在 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" />
themes.xml // litemod/normal
<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 // 黑暗 mod/night
<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>
好的,我的问题得到了答案,实际上我的应用程序已经有深色元素,当我向图像视图或更多元素添加白色背景时,它在黑暗中变为深灰色 mod我不想要的设备,所以我找到了解决这个问题的方法
步骤 1
删除值中的night/dark theme.xml
步骤 2
在normal/lighttheme.xml中的值改变
<style name="Theme.MyAppNotFinal" parent="Theme.MaterialComponents.DayNight.NoActionBar">
至
<style name="Theme.MyAppNotFinal" parent="Theme.MaterialComponents.Light.NoActionBar">
步骤 3
在同一个 theme.xml // light/normal 主题中
添加这一行
<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>
这个方法对我有用,如果还有人有问题,请检查下面的问题,它有很多答案希望它对你有用
Question
我想在 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" />
themes.xml // litemod/normal
<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 // 黑暗 mod/night
<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>
好的,我的问题得到了答案,实际上我的应用程序已经有深色元素,当我向图像视图或更多元素添加白色背景时,它在黑暗中变为深灰色 mod我不想要的设备,所以我找到了解决这个问题的方法
步骤 1
删除值中的night/dark theme.xml
步骤 2
在normal/lighttheme.xml中的值改变
<style name="Theme.MyAppNotFinal" parent="Theme.MaterialComponents.DayNight.NoActionBar">
至
<style name="Theme.MyAppNotFinal" parent="Theme.MaterialComponents.Light.NoActionBar">
步骤 3
在同一个 theme.xml // light/normal 主题中
添加这一行
<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>
这个方法对我有用,如果还有人有问题,请检查下面的问题,它有很多答案希望它对你有用
Question