Parth Anjaria
Parth Anjaria

Reputation: 3971

Change thickness of checkbox

I am using custom AppCompatCheckBox, but i need to change the thickness and color border of the checkbox, which should look like this :

enter image description here

Upvotes: 2

Views: 3370

Answers (2)

Kartik Shah
Kartik Shah

Reputation: 916

Please make a drawable using this code which shows the checkbox :

draw_chackbox.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>    
<layer-list>  
<item>    
<shape android:shape="rectangle">
<padding android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp"/>    
<corners android:radius="4dp"/>
<size android:height="24dp"
android:width="24dp"/>
<stroke android:color="@color/gray_default_font"
android:width="1dp"/>
</shape>    
</item>    
</layer-list>   
</item>
</selector>

and add this drawable in the check box property using

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

add this in main layout. hope it will help you.

Upvotes: 2

Fenil Patel
Fenil Patel

Reputation: 1546

You just need to set the related drawables and set them in the checkbox:

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

Here's a good tutorial about this.

Upvotes: -1

Related Questions