How to change CheckBox text color in android using XML

How to set #color code to check box and create custom check box inside android app dynamically.

In this tutorial we are creating three checkbox with different text colors using android:textColor=” “ attribute on checkbox tag. So here is the complete step by step tutorial for How to change CheckBox text color in android using XML.

android-project-download-code-button

How to change CheckBox text color in android using XML.

Code for MainActivity.java file.

 package com.checkboxtextcolorchange_android_examples.com;

import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;

public class MainActivity extends Activity {

 CheckBox android,php,blogger;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 }

}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.checkboxtextcolorchange_android_examples.com.MainActivity" >

 <CheckBox
 android:id="@+id/checkBox2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_above="@+id/checkBox1"
 android:layout_centerHorizontal="true"
 android:text="Android"
 android:textColor="#fd0000" />

 <CheckBox
 android:id="@+id/checkBox1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignLeft="@+id/checkBox2"
 android:layout_centerVertical="true"
 android:text="PHP"
 android:textColor="#0c00fd" />

 <CheckBox
 android:id="@+id/checkBox3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignLeft="@+id/checkBox1"
 android:layout_below="@+id/checkBox1"
 android:text="Blogger"
 android:textColor="#0cfd00" />

</RelativeLayout>

Screenshot:

How to change CheckBox text color in android using XML

Click here to download How to change CheckBox text color in android using XML project with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *