Custom CheckBox Colors

Nathan Sokalski 4,126 Reputation points
2021-09-08T23:08:15.497+00:00

I have a CheckBox for which I want to change the color inside the box. Setting android:background changes the entire background, including the area surrounding the square, but I only want to change the color of the inside of the square. Is there a way to change all the components of the CheckBox independently?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,326 questions
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,951 Reputation points
    2021-09-09T08:05:30.65+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    but I only want to change the color of the inside of the square

    We cannot change the color of the square space inside the checkBox because the space works as an outside frame instead of a whole square area. Please see the below code, I add background for the parent layout and we can see that the square is like hollow.

       <LinearLayout ...  
           android:orientation="vertical"  
           android:background="#3498">  
           <CheckBox  
                   android:layout_width="wrap_content"  
                   android:layout_height="wrap_content"/>  
       </LinearLayout>  
    

    130694-screenshot-2021-09-09-160109.png

    It's avialable to change the color of the 'frame', try to define the style in the styles.xml.

       <style name="MyCheckBox" parent="AppTheme">  
         <item name="colorControlNormal">@color/theColor</item>  
         <item name="colorControlActivated">@color/theColor</item>  
       </style>  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful