![](/img/trans.png)
[英]How can I set the background of an android layout to a color plus an image?
[英]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
问题代码是名为c8
的color
值,在布局中的背景属性中使用
当我用drawable替换他时,问题不存在。
我该如何解决这个问题?
请检查您的颜色值@color/c8 。 您的颜色c8值可能是错误的。 尝试另一种颜色,它是工作。 尝试使用android:background="@android:color/black" 。 如果它有效,那么我确定您的颜色值是错误的。 您不能使用像0x7f0b0028这样的十六进制颜色值。
它应该可以正常工作,我知道可能导致问题的唯一原因是:
您提供的颜色属性名称不正确。
不支持您在颜色值文件夹中赋予属性的值。
您在您尝试绘制的 xml 项目中多次写入背景属性。
您使用的模拟器不支持此颜色。
请务必检查所有这些原因,如果在确定所有这 4 个原因后您仍然有问题,请联系我们,我们将尝试进一步调查您的问题。
最好的问候, Lidor
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.