Change App Background Colour in the Android Studio - Android Hire
Coding Tutorials

Change App Background Colour in the Android Studio

Aditya Singh
In this tutorial, we will take about how you can change app background colour in the android studio using the Radio Button inside Radio Group.

Developing boring Apps and publishing them just the sake for it won't help you to gain many downloads for your App and maybe you would end up having bad ratings for your App on the Google Play Store.

People love dynamic Apps, not just static Apps. If your app is just a display -show type App people would just download it and would delete it eventually as the app would seem too plain.

Change App background colour in the Android Studio

Change App Background color in the Android Studio

I would give you full code below at the end of the post including XML file along with the main Java file.

In this tutorial, we would put three radio buttons with each labelled with different colour names. Once a user clicks on a particular Radio button. The background of the App would change according to the colour mentioned beside the radio button.

Read More: Google Login And Registration For Android Using Firebase Authentication

Activity_main.xml

        

As stated above in the post that we are going to put three radio buttons, I have included three RadioButton tags each one having its text color set to different ones.

You have to put RadioButton inside the RadioGroup Tags.

Also, note that we have given android:id within the tag of RadioButton, as well as layout_width and layout_height, is also set to wrap_content.

How To Change App Background Colour Using Java

So now coming to MainActivity file. In order to initiate color change, we have used a switch case (having three cases .. one for each color respectively).

As you can see from the code I have mentioned color codes in Hexa format

  • #EC4849 for RED
  • #3498DB for BLUE
  • #f39c12 for ORANGE

In order to change the color of the background once the radio button is activated, we have used onCheckedChanged function and setOnCheckedChangeListener on radioGroup.

MainActivity.Java

package androidhire.com.bgchanger;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;

public class MainActivity extends AppCompatActivity {

    RelativeLayout layout; RadioGroup radioGroup;
    // androidhire.com


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        layout = findViewById(R.id.mainlayout);
        radioGroup = findViewById(R.id.rmain);

        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.r_red:
                        layout.setBackgroundColor(Color.parseColor("#EC4849"));
                        break;

                    case R.id.r_blue:
                        layout.setBackgroundColor(Color.parseColor("#3498DB"));
                        break;

                    case R.id.r_orange:
                        layout.setBackgroundColor(Color.parseColor("#f39c12"));
                        break;
                }
            }
        });
    }
}

How To Change App Background Colour Using Kotlin

What you have to do to just make a kotlin file and import the kotlin plugin to do the configuration. After the import of the kotlin plugin make kotlin file. Right-click on a package and click on NEW -> Kotlin File. Copy and paste below code in your kt file.

MainActivity.kt

package androidhire.com.myapplication

import android.graphics.Color
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.RadioGroup
import android.widget.RelativeLayout

class MainActivity : AppCompatActivity() {

    internal lateinit var layout: RelativeLayout
    internal lateinit var radioGroup: RadioGroup

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        layout = findViewById(R.id.mainlayout)
        radioGroup = findViewById(R.id.rmain)

        radioGroup.setOnCheckedChangeListener { group, checkedId ->
            when (checkedId) {
                R.id.r_red -> layout.setBackgroundColor(Color.parseColor("#EC4849"))

                R.id.r_blue -> layout.setBackgroundColor(Color.parseColor("#3498DB"))

                R.id.r_orange -> layout.setBackgroundColor(Color.parseColor("#f39c12"))

            }
        }
    }
}

ScreenShot

Result

Thus you can see that upon clicking on different radio buttons the background colour is changing accordingly. This would make your App look attractive if you are a beginner in Android Development. Do try these on your own.

Thanks a lot guys for following our series on Android Tutorials. If you want a tutorial on any topic do let us know in the comments section below. We would try to upload it here on AndroidHire.

Aditya Singh's profile picture

Aditya Singh

With over seven years of experience, I help people understand technology through clear and insightful articles. I cover the latest in technology, mobile devices, PCs, how-tos, guides, news, and gadget reviews, always staying updated to provide accurate and reliable information.

Related Posts

7 Top Samsung Galaxy Ring Alternatives for 2025

7 Top Samsung Galaxy Ring Alternatives for 2025

Tired of waiting for the Samsung Galaxy Ring to hit the market? You’re not alone. The smart ring market already has many impressive alternatives available now, despite the buzz around Samsung’s upcoming smart ring. These devices pack advanced health tracking and contactless payment features that might surpass Samsung’s planned offerings. The current lineup of smart […]

What Is Quiet Mode on Instagram and How to Activate It

What Is Quiet Mode on Instagram and How to Activate It

Ever wondered what Quiet Mode on Instagram is all about? This simple yet powerful Instagram feature helps you take a break from the constant buzz of notifications and focus on what truly matters. Whether you’re striving for better work-life balance, dedicating time to studying, or simply trying to disconnect from social media distractions, Quiet Mode […]

How to Make a Bed in Minecraft (Step-by-Step Guide)

How to Make a Bed in Minecraft (Step-by-Step Guide)

A bed in Minecraft is very important. It lets you skip the night and set your spawn point, so if you die, you will return to your bed instead of the original world spawn. This guide will show you how to gather materials, craft a bed, and set your spawn point. We’ll also show you how to customize your bed, build bunk […]

10 Best MMORPG Games For Android

10 Best MMORPG Games For Android

Not too long ago, MMORPG games and powerful gaming consoles were mostly exclusive to PCs. They required high-end graphics and systems to deliver their immersive gameplay. But times have changed. With the rise of gaming-oriented smartphones, you can now enjoy PC-like gaming experiences on your Android device. Thanks to these technological advancements and faster internet […]

Roblox: Fruit Battlegrounds codes (January 2025)

Roblox: Fruit Battlegrounds codes (January 2025)

Fruit Battlegrounds codes are all about getting more gems and help you to shoot up your rank in this One Piece anime-inspired game. This Fruit Battlegrounds was made by Popo developer. It is an action-packed game where players battle it out using unique fruit-based abilities. With constant updates, new fruits, and exciting challenges, it’s a fruity frenzy you won’t […]

Roblox: Ultimate Football Codes (January 2025)

Roblox: Ultimate Football Codes (January 2025)

Want to get some extra items for Ultimate Football in Roblox? You’ve come to the right place! Here’s the latest list of codes to help you score touchdowns and look stylish on the field. These codes offer free rewards such as coins and cosmetics to enhance your gameplay. What are Ultimate Football Codes? Ultimate Football […]

Roblox: Da Hood Codes (January 2025)

Roblox: Da Hood Codes (January 2025)

Are you a fan of Roblox games, in this article we will look at the Roblox Da Hood Codes for December 2024 that will help you unlock exclusive items, improve your gameplay and dominate the streets of Da Hood. You can feel that the game is inspired by the Grand Theft Auto series and there […]