mardi 7 février 2017

checkbox and radio with svg custom button as in android

I am using vector drawable(svg) files for Checkbox and radio button custom button. I cannot able to set the button on those composnent.

 <CheckBox android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:button="@drawable/checkbox_button_bg"
           android:checked="true"
           android:padding="@dimen/min_padding"
           android:layout_margin="@dimen/min_margin"
           android:text="Do you need recurring" />

 <RadioButton android:id="@+id/rdbtnNever"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:padding="@dimen/most_min_padding"
              android:button="@drawable/radio_button_bg"
              android:text="Never"/>

drawable/radio_button_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://ift.tt/nIICcg" >
<item
    android:drawable="@drawable/radio_btn_select"
    android:state_checked="true"
    android:state_pressed="true" />
<item
    android:drawable="@drawable/radio_btn_select"
    android:state_pressed="true" />
<item
    android:drawable="@drawable/radio_btn_select"
    android:state_checked="true" />
<item
    android:drawable="@drawable/radio_btn_unselect" />
</selector>

here radio_btn_select and radio_btn_unselect is vector drawable

And i have done for checkbox as like below.

checkbox_button_bg.xml

 <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://ift.tt/nIICcg" >
  <item
    android:drawable="@drawable/checkbox_check"
    android:state_checked="true"
    android:state_pressed="true" />
<item
    android:drawable="@drawable/checkbox_check"
    android:state_pressed="true" />
<item
    android:drawable="@drawable/checkbox_check"
    android:state_checked="true" />
</selector>

here checkbox_check is vector drawable when i run the program, xml inflating exception raised, and which goes off when i remove the android:button line in both component. so, my doubt is, how to use the vector drawable's in these components.?

Aucun commentaire:

Enregistrer un commentaire