简体   繁体   中英

Android Java can't find drawable inside XML File Button

I developed my app on Android 23 (Marshmallow) with backward compatiblity to 19 (KitKat)

After providing my app to collegues I got response that Android 19 and 22 the app is always closing down.

I found that the following code generated the problem in 19 and 22 (23 is working like a charm):

<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

Removing the drawable part solved this button but stuck with the next button with drawable in the XML file. I tried if the drawable is accessable with the following menue entry:

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

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. Comparing the build.gradle (Module:app) I found that

vectorDrawables.useSupportLibrary = true

was not mentioned in the test app. After removing the line in my app it worked as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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