Change status bar color in KITKAT devices like lollipop material design

Introduction:

      Here I am going to change the background color of status bar in kitkat. Basically all android device has black color in status bar, but now i want to change it to some other colors in status bar.


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.

Demo:

Code:

Steps 1:

Create a new Android Project with Target SDK version 19. If your project already exists         then just change the Target SDK version.


 Add Appcompat v7 lib to your workspace and add this lib to build path of your project.You    can find this lib at sdk\extras\android\support\v7.


Set Project build target to version 19.


There should be only 2 values folder in res folder.

   1.values
   2.values-v19


values/styles.xml should be as below.
<resources>

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/textColorPrimary</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>

<style name="AppTheme" parent="AppTheme.Base"></style>
</resources>


values-v19/style.xml should be as below
<resources>

<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="androidwindowNoTitle">true</item>
</style>
</resources>


Here,

<item name="android:windowTranslucentNavigation">false</item>  is used to hide the footer navigation bar background.


<item name="android:windowTranslucentStatus">true</item>  is used to hide the status bar background.

activity_main.xml

Create Relativelayout and set background color what you want to like to see in status bar. 


<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" >

<RelativeLayout
android:id="@+id/statusbar"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_alignParentTop="true"
android:background="@color/colorPrimaryDark" >
</RelativeLayout>

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Kitkat Status bar like material design" />


</RelativeLayout>


Now this statusbar layout will display in all versions of android OS. so we need to set condition for statusbar only display in kitkat devices only because this layout only will display in status bar background. 

So in your all activity you have to put below condition then only we avoid to display this custom statusbar in other OS versions.

package com.example.kitkatstatusbar;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;

public class MainActivity extends Activity {

RelativeLayout statusbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
statusbar=(RelativeLayout)findViewById(R.id.statusbar);
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT)
{
statusbar.setVisibility(View.VISIBLE);
}
else
{
statusbar.setVisibility(View.GONE);
}
}
}


Happy Coding...
Previous
Next Post »

3 comments

Write comments
Akhil0290
AUTHOR
August 11, 2016 at 8:11 PM delete

how can i change the battery icon on kitkat can u help me
I want to change the battery icon to emojis

Reply
avatar
goodgamer.mn
AUTHOR
November 29, 2016 at 7:12 PM delete

you should find the systemui.apk in /system/app or /system/priv-app folder and copy to any folder. After, rename SystemUI.apk to SystemUI.zip and extract it. /SystemUI/res/drawable_xhdpi/(if your phone's display dpi 320) or /SystemUI/res/drawable_xxhdpi/ (if dpi=480) and find the battery picture and theme it. After, compress to SystemUI.zip
and copy to system/app or system/priv-app (need a root permission) and restart your phone.

Reply
avatar
Unknown
AUTHOR
October 27, 2017 at 3:27 AM delete

in style-v19
...
true
...

Reply
avatar