Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java
  • Android
  • Kotlin
  • Flutter
  • Dart
  • Android with Java
  • Android Studio
  • Android Projects
  • Android Interview Questions
Open In App
Next Article:
How to Change the Color of the Status Bar in Flutter Application?
Next article icon

How to Change the Color of Status Bar in an Android App?

Last Updated : 02 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A Status Bar in Android is an eye-catching part of the screen, all of the notification indications, battery life, time, connection strength, and plenty of things are shown here. An Android user may look at a status bar multiple times while using an Android application. It is a very essential part of the design that the color of the status bar should follow the color combination of the layout. You can look out at many Android apps on your phone and can see how they changed it according to their primary colors.

Status_Bar

Methods to Change the Color of the Status Bar

There can be multiple ways for changing the status bar color but we are going to tell you about the best hand-picked two methods which you can use either in Java or Kotlin. The two easy methods are mentioned below:

  • Creating using a New Theme
  • Using setStatusBarColor Method

Creating a New Theme

You can follow this method in apps that are built with Kotlin or Java. It will work in both.

Step 1: Create New Projects

Open Android Studio and start a new project by selecting an empty activity. Give it a name of your choice, then select your language and API level. At last click on finish.

Step 2: Navigating/Creating styles.xml File

Find an XML file called styles.xml by navigating res/values/styles.xml . And in the case, you don’t find a style.xml file create styles.xml in the location res/values/styles.xml .

Note: Learn to create styles.xml file from this article .

Step 3: Make Changes in colors.xml File

Find another XML file by navigating res/values/colors.xml , and also add that color here which you want to change for the status bar.

XML
<?xml version="1.0" encoding="utf-8"?> <resources>     <color name="black">#000000</color>     <color name="white">#FFFFFFFF</color>     <color name="purple">#A203FF</color>       <color name="color-Primary">#6200EE</color>       <color name="color-PrimaryDark">#3700B3</color>       <color name="color-Accent">#03DAC5</color> </resources> 


These are the color code for the colors which we are either using or can use.

Step 4: Adding the Code in the styles.xml File

Now in the style.xml file, add the below code just before the </resources> tag and change the colors of it as your choice. ColorPrimaryDark is always going to be responsible for your status bar color.

XML
<?xml version="1.0" encoding="utf-8"?> <resources>     <style name="DemoTheme" parent="Theme.AppCompat.Light.NoActionBar">                  <!-- Customize your theme here. -->         <item name="colorPrimary">@color/color-Primary</item>         <item name="colorAccent">@color/color-Accent</item>                    <!-- Defining that new color in ColorPrimaryDark -->         <item name="colorPrimaryDark">@color/color-PrimaryDark</item>     </style> </resources> 


You can do the same with android:statusBarColor but it will work only in above API Level 21. ColorPrimaryDark for the status bar will also not support in API Level 19. By default in most of the API Levels, ColorPrimaryDark will be the default color for statusBarColor, So it is good to go with changing ColorPrimaryDark.

Tip: You can create multiple themes and you can use them in any activity. In any theme, There is a set of colors that needs to be defined, you can also create new colors in the colors.xml file in the same directory and use it on the styles.xml file.

Step 6: Adding the New Theme to the Application

Now go to the manifest/AndroidManifest.xml and here search the activity for which you want to apply that theme or change the color of the status bar. and add an attribute to AndroidManifest.xml file.

android:theme = "@style/DemoTheme"

That’s done! Check your application by running it on an emulator or a physical device.

Using setStatusBarColor Method

This method can be only used in the above API Level 21. Officially status bar color is not supporting below API Level 21. Although, Here we added an if condition, because in case if you haven’t selected above or equal to API 21 then it will check the android API Version, and then it will execute the code. It will not change the color of the status bar is below API Level 21 but the rest code will work well.

Step 1: Create a New Projects

After opening the android studio and creating a new project with an empty activity.

Step 2: Update and Add Color in the colors.xml file

Navigate to res/values/colors.xml , and add a color that you want to change for the status bar. Add the color mentioned below:

<color name="colorPrimaryDark">#3700B3</color>

Step 3: Add Code Snippet to Update Status Bar Color

In your MainActivity, add this code in your onCreate method. Don’t forget to replace your desired color with colorName .

Java
if (Build.VERSION.SDK_INT >= 21) {             Window window = this.getWindow();             window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);             window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);             window.setStatusBarColor(this.getResources().getColor(R.color.colorPrimaryDark));         } 
Kotlin
if (Build.VERSION.SDK_INT >= 21) {             val window = this.window             window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)             window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)             window.statusBarColor = this.resources.getColor(R.color.colorPrimaryDark)         } 


Step 4: Try running your application on an android emulator or a physical device. See the changes.


Click Here to Learn More about Android Development



Next Article
How to Change the Color of the Status Bar in Flutter Application?
author
encrypter09
Improve
Article Tags :
  • Android
  • Java
  • Kotlin
  • Android-Bars
  • Java-Android
  • Kotlin Android
Practice Tags :
  • Java

Similar Reads

  • How to change the color of Action Bar in an Android App?
    Customizing the Action Bar allows you to enhance the visual appeal of your Android app. In this article, you will learn how to change the colour of the Action Bar in an Android App. Basically, there are two ways to change color. By changing styles.xml file:Just go to res/values/styles.xml fileedit t
    2 min read
  • How to Change Text Color of Toolbar Title in an Android App?
    In an Android app, the toolbar title present at the upper part of the application. Below is a sample image that shows you where the toolbar title is present. In the above image, you may see that the color of the Toolbar Title is white which is by default. So in this article, you will learn how to ch
    2 min read
  • How to Change Font of Toolbar Title in an Android App?
    Google Fonts provide a wide variety of fonts that can be used to style the text in Android Studio. Appropriate fonts do not just enhance the user interface but they also signify and emphasize the purpose of the text. In this article, you will learn how to change the font-family of the Toolbar Title
    2 min read
  • How to Change the ProgressBar Color in Android?
    In this article, we will see how we can add color to a ProgressBar in android. Android ProgressBar is a user interface control that indicates the progress of an operation. For example, downloading a file, uploading a file on the internet we can see the ProgressBar estimate the time remaining in oper
    3 min read
  • How to Change the Color of the Status Bar in Flutter Application?
    Flutter is an open-source UI toolkit developed and maintained by Google. It is used by big companies like Airbnb, Alibaba, and Google itself to serve billions of users around the globe. Status Bar is the topmost area of the screen which is home to the Battery Indicator, Network Status, Time, Notific
    1 min read
  • How to Change the ListView Text Color in Android?
    In Android, a ListView is a UI element used to display the list of items. This list is vertically scrollable and each item in the ListView is operable. A ListView adapter is used to supply items from the main code to the ListView in real-time. By default, the TextView font size is 14 sp and color is
    3 min read
  • How to Change the Default Icon of Android App?
    In order to get the app published in stores like Google Play Store, Amazon App Store, etc, or if you just want to personalize the app, the default icon can be changed. We can change the icon of the Android App by using Android Studio itself and by following the below steps: Step 1: Create Android St
    2 min read
  • How to Change Color of Logcat in Android Studio?
    In this article, you will see how to change the color of Logcat. Before moving further let's know about Logcat. A Logcat is a command-line tool that dumps the system log messages. Suppose you are developing an application that contains 3000 lines of code and now after running the application it cras
    2 min read
  • How to Change Background Color of ListView Items in Android?
    In Android, a ListView is a layout element that is used to display items in a list. This is the simplest form of displaying a list or array of items and one can choose from pre-developed layouts for displaying an element without creating a separate layout unlike in other similar views. Each item in
    2 min read
  • Android - How to Change the Color of Alternate Rows in RecyclerView
    RecyclerView is an essential ViewGroup used in Android to display a list of items. It provides a flexible and highly customizable way of implementing a list that can be presented as a grid or a list. In this project, we will be working with RecyclerView to change the color of alternate rows. Typical
    10 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences