banner



How To Change Notification Bar Theme On Android

A Status Bar in Android is an eye-catching part of the screen, all of the notification indication, battery life, fourth dimension, connection strength, and enough of things shows here. An Android user may look at a status bar multiple times while using an Android awarding. Information technology 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 wait out to many android apps on your telephone and tin see how they changed it according to its primary colors. There can exist multiple ways for irresolute the condition bar color simply we are going to tell you nigh the best hand-picked two methods which you can use either in Java or Kotlin.

Method 1: Creating a New Theme

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

Step 1: Open Android Studio and start a new project by selecting an empty activity. Give information technology a name of your choice, then select your language and API level. At last click on terminate.

Step two: Find an XML file called styles.xml by navigating res/values/styles.xml.

Pace 3: Find some other XML file by navigating res/values/colors.xml, and also add that color here which yous desire to change for the status bar.

Pace 4: Now in the style.xml file, add the below code merely before the </resources> tag and change the colors of information technology every bit your choice. ColorPrimaryDark is e'er going to be responsible for your status bar color.

XML

< mode name = "DemoTheme" parent = "Theme.AppCompat.Light.NoActionBar" >

< item name = "colorPrimary" >@color/colorPrimary</ item >

< detail proper name = "colorPrimaryDark" >@colour/colorOfStatusBar</ detail >

< item proper name = "colorAccent" >@colour/colorAccent</ item >

</ style >

You lot can do the same with android:statusBarColor just it will piece of work only in higher up API Level 21. ColorPrimaryDark for the status bar will also non support in API Level 19. Past 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 yous can use them in any activity. In any theme, In that location is a prepare of colors that needs to exist divers, you can also create new colors in the colors.xml file in the same directory and use it on the styles.xml file.

Step half dozen: Now go to the manifest/AndroidManifest.xml and here search the activity for which you desire to utilize that theme or modify the colour of the status bar. and add together an attribute android:theme="@style/DemoTheme".

That's washed! Cheque your application by running it on an emulator or a physical device.

Method 2: Using setStatusBarColor Method

This method can be simply used in the above API Level 21. Officially status bar color is not supporting beneath API Level 21. Although, Hither we added an if condition, considering in case if you haven't selected above or equal to API 21 then it will check the android API Version, and then information technology will execute the code. Information technology will not change the color of the status bar is beneath API Level 21 but the balance code will piece of work well.

Step 1: Subsequently opening the android studio and creating a new project with an empty activity.

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

Step three: In your MainActivity, add together 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)

}

Pace 4: Endeavor running your awarding on an android emulator or a physical device. See the changes.

Output for both the methods will be the same:



Source: https://www.geeksforgeeks.org/how-to-change-the-color-of-status-bar-in-an-android-app/

Posted by: quirozstroardlean1982.blogspot.com

0 Response to "How To Change Notification Bar Theme On Android"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel