2

I am using vector drawable(svg) files for Checkbox and radio button with custom design. I can't able to set the button on those component.

 <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://schemas.android.com/apk/res/android" >
<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://schemas.android.com/apk/res/android" >
  <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?

UPDATE

I have added following code in app and vector drawable completely working fine for Imageview src adding. with the help of app:srcCompat="@drawable/mic"

 defaultConfig {
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    vectorDrawables.useSupportLibrary = true
}
Noorul
  • 3,386
  • 3
  • 32
  • 54
  • Can you please explain where you added the `app:srcCompat` ? – SagiLow Apr 19 '17 at 21:30
  • Yes thank you for response.i have added as drawable in selector. Here radio_btn_select ,radio_btn_unselect and checkbox_check is vector drawables – Noorul Apr 20 '17 at 03:54
  • Thanks for replying. However, I'm not I understand. This issue : http://stackoverflow.com/questions/36741036/android-selector-drawable-with-vectordrawables-srccompat says it's not possible to use `VectorDrawable` in selector, and even you did use it, where you used the `app:srcCompat` ? May you update the question or answer it with the full solution ? Thank you – SagiLow Apr 20 '17 at 10:25
  • i don't know about this solution. just i tried.nonetheless it's not working. so i posted the question here. I don't know whether your solution link work or not since you said it's not possible. I will try. but at the time i managed with png file only. not with svg. – Noorul Apr 20 '17 at 11:51
  • Hello @Noorul, were you able to achieve the desired result? – Tushar Gogna May 17 '19 at 09:51
  • Iam using AS3.4. here , vector drawables supports on this – Noorul May 17 '19 at 10:26

1 Answers1

2

These days there is a property app:buttonCompat on the CompatCheckbox which works the same as app:srcCompat. It solved my issue with no vector button appearing as checkbox button on Android 4.x.

Peterdk
  • 15,625
  • 20
  • 101
  • 140