简体   繁体   English

颜色值可绘制资源问题

[英]color value drawable resource issue

I have an image that is 1900*1200 in a folder called drawable-sw600dp that id like to have used on a nexus 7. When I try to run the app the main activity the screen is white and I get the following error: 我在一个名为drawable-sw600dp的文件夹中有一个1900 * 1200的图像,它就像在nexus 7上使用的那样。当我尝试运行应用程序主要活动屏幕为白色时,我收到以下错误:

java.lang.NumberFormatException: Color value '@drawable-sw600dp/background5' must start with #
at com.android.layoutlib.bridge.impl.ResourceHelper.getColor(ResourceHelper.java:71)
at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:248)
at android.content.res.BridgeTypedArray.getDrawable(BridgeTypedArray.java:782)

Could it be that the image is too large to use? 可能是图像太大而无法使用? Or what could cause this error to happen? 或者可能导致此错误发生的原因是什么?

This is in my activity_main.xml where the background is set: 这是在我的activity_main.xml中设置了背景:

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background5"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:id="@+id/MainLayout"
tools:context=".MainActivity">

In my other folders drawable-hdpi,-mdpi there is no problem. 在我的其他文件夹drawable-hdpi,-mdpi没有问题。 However I made the .jpg image a higher resolution and now it creates this error, thats why I suspect the high resolution is causing the issue. 然而,我使.jpg图像的分辨率更高,现在它产生了这个错误,这就是为什么我怀疑高分辨率导致问题。

Remove the '-' in the file name. 删除文件名中的“ - ”。

NOTE: '-' is not a valid file-based resource name character: File-based resource names must contain only lowercase az, 0-9, or underscore 注意:' - '不是有效的基于文件的资源名称字符:基于文件的资源名称必须仅包含小写az,0-9或下划线

As mentioned by android doc jpg is not supported. 正如android doc jpg所述,不支持。 Use png instead: 请改用png:

A drawable to use as the background. 一个drawable用作背景。 This can be either a reference to a full drawable resource (such as a PNG image, 9-patch, XML state list description, etc), or a solid color such as "#ff000000" (black). 这可以是对完全可绘制资源的引用(例如PNG图像,9补丁,XML状态列表描述等),也可以是纯色,例如“#ff000000”(黑色)。

Some people have mentioned restarting Eclipse has worked, but that didn't work for me. 有人提到重启Eclipse已经有效,但这对我没用。

Instead, I found that I had to simply rename the image file so that it did NOT start with a number. 相反,我发现我必须简单地重命名图像文件,以便它不以数字开头。 All icons in the Android Developer Icon Pack start with a number, and I had just copied the one over. Android Developer Icon Pack中的所有图标都以数字开头,我刚刚复制了一个。 It appears that if the file starts with a number, it is assumed to be the start of a hexadecimal color value, and hence looks for the # symbol. 似乎如果文件以数字开头,则假定它是十六进制颜色值的开始,因此查找#符号。

working with: Eclipse Juno 3.7.2, Android SDK 21.1 使用:Eclipse Juno 3.7.2,Android SDK 21.1

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

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