color value drawable resource issue

匆匆过客 提交于 2020-01-01 08:06:41

问题


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:

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:

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. 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.


回答1:


Remove the '-' in the file name.

NOTE: '-' is not a valid file-based resource name character: File-based resource names must contain only lowercase a-z, 0-9, or underscore




回答2:


As mentioned by android doc jpg is not supported. Use png instead:

A drawable to use as the background. 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).




回答3:


Some people have mentioned restarting Eclipse has worked, but that didn’t work for me.

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. 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



来源:https://stackoverflow.com/questions/20599262/color-value-drawable-resource-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!