资源不是可绘制的 [英] Resource is not a Drawable
问题描述
此代码在Emulator(API 18)上导致强制关闭异常,并在ASUS Nexus 7(API 21)中工作
This code causes force close exception on Emulator(API 18) and works in ASUS Nexus 7(API 21)
<View
android:layout_width="400dp"
android:layout_height="2dp"
android:layout_marginTop="30dp"
android:background="@color/light_gray" />
如果我将@color/light_gray
替换为#EBEBEB
,则在两种设备上均可正常运行.
If I am replacing @color/light_gray
with #EBEBEB
works perfectly on both device.
例外是
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f080060 a=-1 r=0x7f080060}
所以我转向以下代码中的drawable
So I moved to drawable on following code,
<Button
android:layout_width="wrap_content"
android:layout_marginTop="30dp"
android:layout_height="wrap_content"
android:ems="10"
android:background="@drawable/login_btn_selector"
android:text="Login"
android:id="@+id/btnLogin" />
这引发了以下异常,
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi-v4/login_btn_selected.xml from drawable resource ID #0x7f020095
所以我试图将login_btn_selected.xml
放在res/drawable-hdpi-v4/
文件夹中,然后说在res/drawable-hdpi/
和res/drawable-hdpi-v4/
之间出现重复文件,所以我从res/drawable-hdpi/
中删除了它,然后再次在相同的资源中找不到异常v4文件夹,
So I tried to place the login_btn_selected.xml
in res/drawable-hdpi-v4/
folder, Then it says duplicate file occur between res/drawable-hdpi/
and res/drawable-hdpi-v4/
, So I removed it from res/drawable-hdpi/
, Then again same resource not found exception in v4 folder,
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi-v4/login_btn_selected.xml from drawable resource ID #0x7f020095
所以最后我来到了 SO .
问题是
-
我想知道是仅在模拟器中还是在真实设备中也存在此问题.
I want to know is this problem in emulator only or in real device too.
如果在真实设备中也意味着我该如何克服呢?
If in real device too means how can I overcome this?
我想使用@color/light_gray
而不是硬编码,而且我想使用可绘制的选择器.
I want to use @color/light_gray
instead of hard coding, Also I want to use drawable selectors.
注意::我已删除并重新创建了模拟器,没有用.同样,我也在API 19模拟器上进行了测试.
NOTE: I have deleted and recreated the Emulator, no use. I have tested on API 19 emulator also, same issue.
任何解决方案都是高度可取的.
Any solution will be highly appreciable.
推荐答案
这是因为我的色彩资源文件位于\res\values-21
文件夹下,现在将其移至\res\values\
文件夹下,现在应用程序运行正常.谢谢朋友.
It is because my color resource file is under \res\values-21
folder, Now moved it to \res\values\
folder, Now app works fine. thank you friends.
这篇关于资源不是可绘制的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!