mercredi 19 avril 2017

Using VectorDrawable as CheckBox background

Recently got a crash report on a device running API 16 saying :

org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector

As far as I've seen, it caused due to a missing support in API 16 for VectorDrawable.
Honestly I had no idea I have such drawables and according to the git log it looks like they were auto-generated as I enabled the vector library.
I want to define a checkbox background, should I leave the VectorDrawable ? If so, how should I support lower API's ? If I remove them, wouldn't they be auto-generated again?

Here is the checkbox declaration:

<CheckBox
    android:id="@+id/reminder_enabled_checkbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_gravity="center"
    android:layout_marginLeft="15dp"
    android:layout_marginStart="15dp"
    android:padding="10dp"
    android:button="@drawable/notification_icon_checkbox" />

Here is the selector : (notification_icon_checkbox) :

<?xml version="1.0" encoding="utf-8"?>
<selector  xmlns:android="http://ift.tt/nIICcg">
    <item android:state_checked="false" android:drawable="@drawable/ic_notifications_none_black_24dp" />
    <item android:state_checked="true" android:drawable="@drawable/ic_notifications_black_24dp" />
    <item android:drawable="@drawable/ic_notifications_none_black_24dp" /> <!-- default state -->
</selector>

The drawable ic_notifications_none_black_24dp is both .png file and VectorDrawable xml file.




Aucun commentaire:

Enregistrer un commentaire