Change icons of checked and unchecked for Checkbox for Android

后端 未结 5 1303
青春惊慌失措
青春惊慌失措 2020-11-27 13:54

Instead of having a check mark for the icon, I want a custom star (I have checked and unchecked icons). Can this be done through a property? Or must I declare a custom widge

相关标签:
5条回答
  • 2020-11-27 14:05

    it's android:button="@drawable/selector_checkbox" to make it work

    0 讨论(0)
  • 2020-11-27 14:10

    This may be achieved by using AppCompatCheckBox. You can use app:buttonCompat="@drawable/selector_drawable" to change the selector.

    It's working with PNGs, but I didn't find a way for it to work with Vector Drawables.

    0 讨论(0)
  • 2020-11-27 14:13

    I realize this is an old question, and the OP is talking about using custom gx that aren't necessary 'checkbox'-looking, but there is a fantastic resource for generating custom colored assets here: http://kobroor.pl/

    Just give it the relevant details and it spits out graphics, complete with xml resources, that you can just drop right in.

    0 讨论(0)
  • 2020-11-27 14:19

    Kind of a mix:

    Set it in your layout file :-

     <CheckBox android:layout_width="wrap_content"
               android:layout_height="wrap_content" 
               android:text="new checkbox"
               android:background="@drawable/checkbox_background" 
               android:button="@drawable/checkbox" />
    

    where the @drawable/checkbox will look like:

    <?xml version="1.0" encoding="utf-8"?>
    
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:state_checked="true" android:state_focused="true"
      android:drawable="@drawable/checkbox_on_background_focus_yellow" />
     <item android:state_checked="false" android:state_focused="true"
      android:drawable="@drawable/checkbox_off_background_focus_yellow" />
     <item android:state_checked="false"
      android:drawable="@drawable/checkbox_off_background" />
     <item android:state_checked="true"
      android:drawable="@drawable/checkbox_on_background" />
    </selector>
    
    0 讨论(0)
  • 2020-11-27 14:19

    One alternative would be to use a drawable/textview instead of a checkbox and manipulate it accordingly. I have used this method to have my own checked and unchecked images for a task application.

    0 讨论(0)
提交回复
热议问题