0

您好,我想知道如何为 ui 元素设置固定颜色,无论 android 设备处于亮模式还是暗模式

在我的情况下,存在一些问题,设备的浅色模式下的视图设置为我在浅色模式下给定的颜色背景,但是当我将设备切换到深色模式时,视图将其颜色更改为我没有设置的深灰色

有什么方法可以解决这个问题,还有关于我将来如何使用每个 ui 元素做到这一点的任何提示

这是我的代码

BottomSheet.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:id="@+id/slidedownview"
        android:layout_width="40dp"
        android:layout_height="3dp"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:layout_marginTop="10dp"
        android:background="@drawable/rounded_corner_bottomsheetline"/>

</RelativeLayout> 

rounded_corner_bottomsheetline

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:endColor="@color/lite_grey"
        android:startColor="@color/lite_grey" />
    <corners
        android:bottomLeftRadius="25dp"
        android:bottomRightRadius="25dp"
        android:topLeftRadius="25dp"
        android:topRightRadius="25dp" />

</shape>

色标

<color name="lite_grey">#e2e2e2</color>

输出 //暗模式

如您所见,视图是我设置的深灰色,我设置的颜色是#e2e2e2

在此处输入图像描述

输出//正常或轻模式

在此处输入图像描述

4

1 回答 1

0

检查themes.xml文件夹并为白天和夜间主题设置相同的颜色

于 2021-07-01T09:48:06.243 回答