简体   繁体   English

Android Java在XML File Button中找不到可绘制对象

[英]Android Java can't find drawable inside XML File Button

I developed my app on Android 23 (Marshmallow) with backward compatiblity to 19 (KitKat) 我在Android 23(棉花糖)上开发了我的应用,向后兼容到19(KitKat)

After providing my app to collegues I got response that Android 19 and 22 the app is always closing down. 在向同事提供我的应用程序后,我得到了有关Android 19和22的应用程序始终关闭的响应。

I found that the following code generated the problem in 19 and 22 (23 is working like a charm): 我发现以下代码在19和22中产生了问题(23的工作原理很简单):

<Button
    android:id="@+id/Profile_Add"
    android:drawableStart="@drawable/ic_add_box_black_24dp"
    android:layout_width="150dp"          
    android:layout_height="wrap_content"
    android:text="@string/Profile_New"/>

It generated the failure: 它产生了故障:

android.content.res.Resources$NotFoundException: File res/drawable/ic_add_box_black_24dp.xml from drawable resource ID xxxxxx android.content.res.Resources $ NotFoundException:来自可绘制资源ID xxxxxx的文件res / drawable / ic_add_box_black_24dp.xml

Removing the drawable part solved this button but stuck with the next button with drawable in the XML file. 删除可绘制部分解决了此按钮,但在XML文件中保留了具有可绘制的下一个按钮。 I tried if the drawable is accessable with the following menue entry: 我尝试使用以下菜单项访问drawable:

<item android:id="@+id/R_Test"
    android:icon="@drawable/ic_add_box_black_24dp"
    android:title="Test"/>

This worked without problems. 这没有问题。

Why is my code working with Android 6.0 but not with 4.4 and 5.1 ? 为什么我的代码只能在Android 6.0上运行,而不能在4.4和5.1上运行?

I generated a new app with ic_add_box_black_24dp.xml in drawable and the mentioned button xml for Android 19. It worked without problems. 我在drawable中使用ic_add_box_black_24dp.xml生成了一个新应用,并为Android 19使用了提到的按钮xml。它可以正常工作。 Comparing the build.gradle (Module:app) I found that 比较build.gradle(Module:app),我发现

vectorDrawables.useSupportLibrary = true

was not mentioned in the test app. 在测试应用中未提及。 After removing the line in my app it worked as expected. 在我的应用中删除该行后,它按预期工作。

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

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