Changing Default Color of Android CheckBox Check Mark

前端 未结 2 1401
Happy的楠姐
Happy的楠姐 2021-01-11 11:35

How do I change the default color of the Android checkbox from green checkmarks to blue for a particular CheckBox?

2条回答
  •  醉梦人生
    2021-01-11 12:21

    Unfortunately, changing the colour isn't a simple attribute. The checkmark is an image, so you have to create a custom image. Take a look at this example

    Create a selector xml file such as this:

    
    
        
        
    
    

    save this xml file in your res\drawables\ folder. Then inside your layout file apply it to your checkBox like this:

    
    

    In this example you'd name your selector xml file "checkbox_selector.xml" and you'd need a star_down.png, and star.png in your drawables folder as well. You can use this technique to create different colored checkboxes by altering the system checkbox images to whatever color you want and referencing the altered png files in a selector.

提交回复
热议问题