我无法使用颜色值来设置布局的背景

I can't use the color value to set the background for the layout

这是我的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/c8"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    tools:context="com.leo.accelerate.activity.SplashActivity">

    <ImageView
        android:layout_marginTop="190dp"
        android:layout_width="146dp"
        android:layout_height="146dp"
        android:src="@mipmap/icon_splash"
        />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="36dp"
        android:src="@mipmap/boost_shanping_name"
        />

</LinearLayout>

我收到错误:

     Caused by: android.content.res.Resources$NotFoundException: Resource "com.leo.accelerate:style/RtlOverlay.DialogWindowTitle.AppCompat" (7f0b0028)  is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0b0028 a=-1 r=0x7f0b0028}

我根据地址值找到问题颜色0x7f0b0028

 find . -type f | xargs grep "0x7f0b0028"

result:
./app-default-release/res/values/public.xml:    <public type="color" name="c8" id="0x7f0b0028" />
./app-default-release/smali/com/leo/accelerate/R$color.smali:.field public static final c8:I = 0x7f0b0028

问题代码是名为c8color值,在layout

中的backgroud属性中使用

当我将他换成drawable时,问题就不存在了

我该如何解决这个问题?

你能检查一下你的颜色值吗@color/c8。您的颜色 c8 值可能有误。尝试另一种颜色,它是工作。尝试 android:background="@android:color/black"。如果它正常工作,那么我确定您的颜色值是错误的。您不能使用像 0x7f0b0028.

这样的十六进制颜色值

它应该工作得很好,我知道这可能会导致问题的唯一原因是:

  1. 您提供的颜色属性名称不正确。

  2. 您在颜色值文件夹中给属性的值是 不支持。

  3. 您在xml项中多次写入背景属性 你正在尝试画画。

  4. 您使用的模拟器不支持此颜色。

请确保检查所有这些原因,如果在确定所有这 4 个原因后您仍然有问题,请联系我们,我们将尝试进一步调查您的问题。

最好的问候,Lidor