Search code examples
androidsvgandroid-support-libraryvector-graphics

Using vector images with android:drawableTop before API level 21


I am working on an application that needs to run on Android devices all the way down to Android Gingerbread (2.3) and seem to have run into some issues displaying an SVG image.

I understand, the support library allows me to use vector images by dropping this line in my app level build.gradle:

vectorDrawables.useSupportLibrary = true

and I can then use a variety of support library classes or the android:srcCompat to display an SVG in an ImageView

The issue you here is that I am not using an ImageView to display my SVG. I am using a TextView with the android:drawableTop attribute to display my SVG as in:

<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/text_no_notes"
        android:textAlignment="center"
        android:drawableTop="@drawable/ic_notepad"
        android:id="@+id/textView"
        android:textAppearance="@style/TextAppearance.AppCompat.Medium.Inverse" />

Since android:drawableTop does not use the support library vector images, the app crashes at runtime on pre "L" devices. Is there a workaround I can use to get android:drawableTop working, or am I stck just splitting up the TextView and use android:srcCompat?


Solution

  • There's no way to use it with the system TextView. (Relevant source code: 5.1.1 / 4.4.4)

    You could use a custom View class, but at this point I think you are better off using a LinearLayout with an ImageView and a TextView.