Change Radio Button background color in android via XML

How to create radio button with background color set in android app.

In this tutorial we are changing the background color of radio button using android:background=” “ attribute. So here is the complete step by step tutorial for Change Radio Button background color in android via XML.

android-project-download-code-button

How to Change Radio Button background color in android via XML.

Code for MainActivity.java file.

package com.changeradiobuttonbackgroundcolor_android_examples.com;
import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

 @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.changeradiobuttonbackgroundcolor_android_examples.com.MainActivity" >

 
 <RadioGroup
 android:id="@+id/radiogroup"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:orientation="vertical"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 
 >
 
 <RadioButton
 android:id="@+id/radioButton1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:text="Android"
 android:background="#fdd101"
 android:padding="15dp"
 />

 <RadioButton
 android:id="@+id/radioButton2"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:text="Blogger"
 android:background="#b9fd01"
 android:padding="15dp" />

 <RadioButton
 android:id="@+id/radioButton3"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:text="PHP"
 android:background="#fd01fa"
 android:padding="15dp" />

 </RadioGroup>
</RelativeLayout>

Screenshot:

Change Radio Button background color in android via XML

Click here to download Change Radio Button background color in android via XML project with source code.

Leave a Reply

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