Search code examples
androidandroid-spinnerandroid-vectordrawableandroid-selector

How to inflate a Vector inside a Selector of a Spinner in Android?


In my app, I'm having this spinner:

<Spinner
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:id="@+id/spinner"
    android:background="@drawable/spinner">
</Spinner>

For the background, I'm using:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item><layer-list>
        //Colors, Shapes and other details

        <item >
            <bitmap android:gravity="bottom|right"
                android:src="@drawable/ic_arrow_drop_down_24dp" />
        </item>
    </layer-list></item>
</selector>

And for ic_arrow_drop_down_24dp, I use:

<vector android:height="24dp" android:tint="#008577"
    android:viewportHeight="24.0" android:viewportWidth="24.0"
    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#FF000000" android:pathData="M7,10l5,5 5,-5z"/>
</vector>

And I'm getting:

android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class Spinner

So I guess the error is because I'm inflating a vector and not bitmap. How to inflate a vector? Thanks!


Solution

  • In the @drawable/spinner is missing the item tag which specifies the shape and the colors of the spinner.