To avoid error: Binary XML file line #XXX: requires a valid src attribute

inside a layer-list, use:

<item android:drawable="@drawable/image" />

instead of:

<item>
  <bitmap android:src="@drawable/image"/>
</item>

You cant have an xml drawable as source for bitmap. Because for example if it was possible, then it could mistakenly create a black-hole by calling xml to itself.

Lets suppose, you have an xml drawable A which has a bitmap whos source is drawable B. But in drawable B, it has a bitmap whos source is drawable A. This will create a circular loop which cant be resolved. That is why you need to provide an image as a source for bitmap to avoid any confusion


Minimum SDK: API 23

drawable/yourDrawable.xml

In the following code I have a vector as a background as the first item and in the second item centered logo with a custom size above the background.

<layer-list
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@drawable/background_in_svg_1">

    </item>
    <item
        android:width="200dp"
        android:height="60dp"
        android:gravity="center_vertical|center_horizontal"
        android:drawable="@drawable/logo_in_svg_2"/>
</layer-list>

Note: The cumulative distribution as of today from API 23 is 84.9%. So you might consider an alternative for lower APIs

GL

Source


If you want to use selector for changing tint attribute, create selector for color only.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/white" android:state_pressed="true" />
    <item android:color="@color/white" android:state_activated="true" />
    <item android:color="@color/green" />
</selector>

And then use it as color in android:tint

<ImageView
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:tint="@color/tint_menu_item"
    android:src="@drawable/ic_menu_home" />