Skip to content
Fix Code Error

How to change the status bar color in Android?

March 13, 2021 by Code Error
Posted By: Anonymous

First of all it’s not a duplicate as in How to change the background color of android status bar

How do I change the status bar color which should be same as in navigation bar.

I want the status bar color to be same as the navigation bar color

enter image description here

Solution

Update:

Lollipop:

public abstract void setStatusBarColor (int color)

Added in API level 21

Android Lollipop brought with it the ability to change the color of status bar in your app for a more immersive user experience and in tune with Google’s Material Design Guidelines.

Here is how you can change the color of the status bar using the new window.setStatusBarColor method introduced in API level 21.

Changing the color of status bar also requires setting two additional flags on the Window; you need to add the FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag and clear the FLAG_TRANSLUCENT_STATUS flag.

Working Code:

import android.view.Window;

…

Window window = activity.getWindow();

// clear FLAG_TRANSLUCENT_STATUS flag:
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

// add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

// finally change the color
window.setStatusBarColor(ContextCompat.getColor(activity,R.color.my_statusbar_color));

Offcial developer reference : setStatusBarColor(int)

Example :material-design-everywhere

Chris Banes Blog- appcompat v21: material design for pre-Lollipop devices!

enter image description here

The transitionName for the view background will be android:status:background.

Answered By: Anonymous

Related Articles

  • AppCompat v7 r21 returning error in values.xml?
  • Android : Fragment doesn't fit into Fragment Container
  • Convert array to nested JSON object - Angular Material tree
  • How to use the new Material Design Icon themes:…
  • Unable to run Robolectric and Espresso with a…
  • Examples of GoF Design Patterns in Java's core libraries
  • How to filter a RecyclerView with a SearchView
  • Fragment Not Showing in the Activity
  • Flutter : How to make every card unique using…
  • Vue.JS & Spring Boot - Redirect to homepage on 404
  • Remove Text from the edit text when edit text is focused
  • Android Layout Animations from bottom to top and top…
  • Error in styles_base.xml file - android app - No…
  • ListView inside ScrollView is not scrolling on Android
  • MaterialCardView is in front of NavigationView. How…
  • How to implement HorizontalScrollView like Gallery?
  • Callback functions in C++
  • Playing HTML5 video on fullscreen in android webview
  • How to set dropdown arrow in spinner?
  • Creating a SearchView that looks like the material…
  • How do I keep only the first map and when the game…
  • Navigation View and Constraint Layout
  • Adding gif image in an ImageView in android
  • onClick for buttons on custom CardView
  • FloatingActionButton example with Support Library
  • Android adding simple animations while…
  • Auto-fit TextView for Android
  • Error inflating class android.support.v7.widget.Toolbar?
  • Button is null object reference (Android Studio)
  • Android ListView headers
  • Getting duplicated cardviews using SwipeRefresh Layout
  • Javax.net.ssl.SSLHandshakeException:…
  • Constraint Layout Vertical Align Center
  • Unable to move from one fragment to another
  • Google Maps Android API v2 - Interactive InfoWindow…
  • Failed to load AppCompat ActionBar with unknown…
  • Interface vs Abstract Class (general OO)
  • Error inflating class…
  • How to download and save an image in Android
  • Trouble with boxes appearing/hiding based on selection
  • Unity color wont assign to ball or what it should be…
  • How to disable Home and other system buttons in Android?
  • What is and how to fix…
  • Changing Icon Color behind ListTile in an…
  • android.view.InflateException: Binary XML file line…
  • How to hide navigation bar permanently in android activity?
  • How to show title in hover - css / jquery
  • What is the difference between Material Design…
  • Why is 2 * (i * i) faster than 2 * i * i in Java?
  • handle clickevent in appbar in fragments android studio
  • Android Push Notifications: Icon not displaying in…
  • java.lang.NullPointerException: Attempt to invoke…
  • Integrate ZXing in Android Studio
  • Item position in RecyclerView only changing when…
  • Vue js vuecli3 application does not work in ie11…
  • image are not showing in image view after selecting…
  • Android new Bottom Navigation bar or BottomNavigationView
  • How to center the content inside a linear layout?
  • Class is not abstract and does not override abstract method
  • Android "gps requires ACCESS_FINE_LOCATION" error,…
  • How to hide toolbar in collapsed mode and show in…
  • Android REST client, Sample?
  • Draw in Canvas by finger, Android
  • Percentage width in a RelativeLayout
  • Is there an addHeaderView equivalent for RecyclerView?
  • How to use ScrollView in Android?
  • How to change status bar color to match app in…
  • Add Items to ListView - Android
  • problem with client server unix domain stream…
  • bootstrap material design and Aurelia
  • Is it possible to make abstract classes in Python?
  • This app won't run unless you update Google Play…
  • Jetpack Compose and Hilt Conflict
  • Programmatically Hide/Show Android Soft Keyboard
  • Android "elevation" not showing a shadow
  • Couldn't load memtrack module Logcat Error
  • Failed linking file resources
  • Navbar not filling width of page when reduced to mobile view
  • CardView not showing Shadow in Android L
  • DatePicker onDateSet method not running
  • Android App crashes on animated gradient background
  • Same Navigation Drawer in different Activities
  • Polymer's Paper Elements & Angular Material
  • Restful API service
  • GridLayout and Row/Column Span Woe
  • Fastest way to iterate over all the chars in a String
  • How to add mixin for height in mwc textfield?
  • C++ OpenGL stb_image.h errors
  • Android + Pair devices via bluetooth programmatically
  • java.lang.RuntimeException: Unable to start activity…
  • Knight's tour Problem - storing the valid moves then…
  • Duplicate ID, tag null, or parent id with another…
  • How to implement a ViewPager with different…
  • Android - How to download a file from a webserver
  • Having trouble with my nav bar/header, It used to…
  • Notification bar icon turns white in Android 5 Lollipop
  • Android app unable to start activity componentinfo
  • What's the difference between AngularJS Material and…
  • Warning: Prop `className` did not match ~ Material…
  • Rails wrong number of arguments error when…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Convert .pem to .crt and .key

Next Post:

PHP Pass variable to next page

Leave a Reply Cancel reply

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

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error