Android layer-list : bitmap issue with app:srcCompat

android vector drawable
bitmap item in layer-list android
android vector icons
android vector drawable in layer-list
android layer-list text
android layer-list margin
android layer-list not showing
android layer-list drawable size

After updating to Studio 2.3 when i tried to create a layer list with a vector drawable it prompt to use app:srcCompat instead of android:src in bitmap.

can any one help me to add vector drawable to layer list ?

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@color/colorWhite" />

<item>
    <bitmap
        android:gravity="center"
        app:srcCompat="@drawable/login">
    </bitmap>

</item>

</layer-list>

Already added

vectorDrawables.useSupportLibrary = true

I found a solution for your problem

Modify second item to this:

<item android:gravity="center" android:drawable="@drawable/login"/>

UPDATE

this will cause crash on API < 21. There is not any better way.

Vector Drawable in Layer List on Older Android Versions, If you look at your layer-list drawable in the Android Studio editor, these attributes will load up VectorDrawableCompat drawables when you use app:srcCompat . You can append Bitmap to item I think this is the best solution This feature defaults to disabled, since enabling it can cause issues with  Questions: After updating to Studio 2.3 when i tried to create a layer list with a vector drawable it prompt to use app:srcCompat instead of android:src in bitmap. can any one help me to add vector drawable to layer list ? <item> <bitmap android:gravity="center" app:srcCompat="@drawable/login"> </bitmap>

I managed to do it the following way:

<item
    android:gravity="center"
    android:drawable="@drawable/login" />

"Splash Screens the Right Way" issue with Andoid 8-9 (vector , On Android 8/9/later it fails with Caused by: android.content.res. the Right Way" issue with Andoid 8-9 (vector drawable launcher icon) as launcher icon. bitmap element inside item element of course doesn't support it API <= 19 doesn't support vector drawables (only ImageView with app:srcCompat). Android layer-list:bitmap issue with app:srcCompat (2) I found a solution for your problem. Modify second item to this: <item android:gravity = "center" android:drawable = "@drawable/login" /> UPDATE. this will cause crash on API < 21. There is not any better way.

Instead of doing :

<item>
    <bitmap
        android:gravity="center"
        app:srcCompat="@drawable/login">
    </bitmap>
</item>

You need to declare the background as follow:

<item
    android:gravity="center"
    app:srcCompat="@drawable/login"/>

Also, make sure that the element app schema is presented:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto">
    ....
</layer-list>

Vector drawables overview, This document explains the overall usage of the vector drawable resources you can use the new app:srcCompat attribute to reference vector drawables as  Android layer-list:bitmap issue with app:srcCompat Java: Scale Mapsforge Map when using online bitmap tiles instead of offline renderer Large Icon Bitmap appears as white square in notification?

Difference between app:srcCompat and android:src in Android's , When using app:srcCompat="#drawable/some_vector" with vectorDrawables. If you visit issue ISSUE 205236, it seems that they will enable in the future but android:src attribute (the IDE will warn you if it's invalid like for the <bitmap> tag). If you’re lucky and you know the exact width of your icons, it should be super-easy. E.g. if your icons for the NavigationDrawer are exactly 24dp wide, this: <TextView android:layout_width="match_parent" android:layout_height="48dp" android:drawableLeft="@drawable/icon" android:drawablePadding="32dp" android:gravity="left|center_vertical" android:paddingLeft="16dp" android:text="TextView

Список слоев Android: проблема с растровым изображением в , вывода, попросите использовать app:srcCompat вместо android:src в bitmap . может ли кто-нибудь помочь мне добавить vector drawable to layer list ? I’ve got a web site that I’m enabling ssl on for a RESTful service. We have registered with RapidSSL, installed the certs, and it passes the RapidSSL checker.I’m able to access the site with various browsers, including the android browsers (built in, firefox and opera) with no problems, no warnings.

AppCompat, Right, so you want to use a vector asset in your app and your We've added support for VectorDrawableCompat here too with the new app:srcCompat attribute. Using this drawable, an example ImageView declaration would be: usage and Configuration updating issues so we it removed in 23.3.0. Android Studio can also convert SVG files to the vector drawable format, as described in using Add multi-density vector graphics. Android 5.0 (API level 21) was the first version to officially support vector drawables with VectorDrawable and AnimatedVectorDrawable, but you can support older versions with

Comments
  • Any luck with this?
  • No. nothing so far
  • ok. I'm going to try something. let me know if you come across something as well.
  • I'm having exact same problem. Still no joy with this?
  • reported as bug issuetracker.google.com/issues/123822220
  • Has anyone found a solution that doesn't make the app crash for API < 21?
  • on some Android versions vector drawable looks ugly (becomes distorted)
  • @user25 Can you say which devices? Or which Api versions?
  • You can add a png for API < 21 this will lead to distorted images though, but it doesnt crash anymore, by now you might considering rasing the minSDK to 21 (targeting 85% of Android phones as of now)
  • error: attribute drawable (aka app.name:drawable) not found
  • I think <item> android:gravity="center" app:srcCompat="@drawable/login" </item> is not valid, did you mean <item android:gravity="center" app:srcCompat="@drawable/login"> </item>?
  • this solution did not work for me for whatever reason. Crashes with: <item> tag requires a 'drawable' attribute or child tag defining a drawable
  • What a random answer! @JoseF Did you even test that yourself?
  • @JoseF well... app:srcCompat="@drawable/login" will never work, it's only for ImageView
  • but we can just use android:drawable="@drawable/login" in item (it even works for vector drawables)