简体   繁体   English

我不能使用颜色值来设置布局的背景

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

this is my 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>

I got the error:我得到了错误:

     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}

I found the problem color according to the address value 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

The problem code is the color value named c8 , It is used in the backgroud property in the layout问题代码是名为c8color值,在布局中的背景属性中使用

When I replace him with a drawable, the problem does not exist.当我用drawable替换他时,问题不存在。

how can I fix this problem?我该如何解决这个问题?

Can you please check your color value @color/c8 .请检查您的颜色值@color/c8 Your color c8 value may be wrong.您的颜色c8值可能是错误的。 Try with another color, it is work.尝试另一种颜色,它是工作。 Try with android:background="@android:color/black" .尝试使用android:background="@android:color/black" If it is working then I'm sure that your color value is wrong.如果它有效,那么我确定您的颜色值是错误的。 You can not use hex color value like 0x7f0b0028 .您不能使用像0x7f0b0028这样的十六进制颜色值。

It should work just fine, the only reasons I know of that might cause a problem are:它应该可以正常工作,我知道可能导致问题的唯一原因是:

  1. the name of the color attribute you provided is incorrect.您提供的颜色属性名称不正确。

  2. the value which you gave the attribute in your color value folder is not supported.不支持您在颜色值文件夹中赋予属性的值。

  3. you wrote the background attribute more than one time in the xml item you're trying to draw.您在您尝试绘制的 xml 项目中多次写入背景属性。

  4. the emulator you're using does not support this color.您使用的模拟器不支持此颜色。

Please make sure to check all of those reasons, if after making sure all of those 4 you still have a problem, contact us and we will try to further investigate your problem.请务必检查所有这些原因,如果在确定所有这 4 个原因后您仍然有问题,请联系我们,我们将尝试进一步调查您的问题。

Best Regards, Lidor最好的问候, Lidor

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM