Monday, January 3, 2011

How to implement your own status bar view...!!

Some of you might be interested in replacing the android provided status bar with their own creative stuffs on top of the phone, instead the standard one provided by android.In this post i am going to explain how you can replace existing android's standard status bar view with your view.

Layout for android status bar is defined in

The inflation part is handled in

Line no 256 ( Roughly )

private void makeStatusBarView(Context context) {
Resources res = context.getResources();
mRightIconSlots = res.getStringArray(;
mRightIcons = new StatusBarIcon[mRightIconSlots.length];

ExpandedView expanded = (ExpandedView)View.inflate(context,, null);
expanded.mService = this;
StatusBarView sb = (StatusBarView)View.inflate(context,, null);


The place where the status bar view added is

public void systemReady() {
final StatusBarView view = mStatusBarView;
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
lp.gravity = Gravity.TOP | Gravity.FILL_HORIZONTAL;
lp.windowAnimations =;

WindowManagerImpl.getDefault().addView(view, lp);

The status bar view which was inflated earlier is added to WindowManager.
WindowManagerImpl.getDefault().addView(view, lp);

In order for your view to be shown, simple, you need to bring in your 'View' instance and add it here at this point. DONE...!!

So simple isn't it...!!

But, well where will you keep your view handling/creating (i mean the .java file), how will you show default status bar notifications( like antenna, wifi, bluetooth ) every thing which a status bar shows now.

1 - Create a folder in /frameworks/base named 'mystatus'
2 - Create java and res folders and create folders inside 'java' as per package names and keep the resources, layouts files you need under res corresponding folders ( drawable-hdpi , layouts )

res->anim ( if any required )

3 - In this way you have all your independent view creation/public exposed apis present in a seperate folder in framework.

package com.mani.mystatus;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.content.res.Resources;

public final class MyStatusBarView extends LinearLayout{

private TextView batterytext;
private TextView batterylevel;
private TextView batterypercentage;

public MyStatusBarView(Context context, AttributeSet attrs){
super(context, attrs);


public MyStatusBarView(Context context){

batterytext = new TextView(context);
batterytext.setText("MANI - My status bar");

batterylevel = new TextView(context);

batterypercentage = new TextView(context);

LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.FILL_PARENT);
LinearLayout.LayoutParams levelParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.FILL_PARENT);
LinearLayout.LayoutParams percentageParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.FILL_PARENT);





public void setBatteryLevel(int level)
String blevel = "";
blevel+= level;



Changes required in

These are the four steps you need to implement.

1- Import the view class
import com.mani.mystatus.MyStatusBarView;

2 - Declare a global variable to MyStatusBarView
MyStatusBarView myStatusBarView;

3 - Create a instance (NOTE: We are passing context obtained in StatusBarService)
myStatusBarView = new MyStatusBarView(mContext);

4 - Add the view instance to WindowManager
WindowManagerImpl.getDefault().addView(myStatusBarView, lp);

I am going to show you how to display battery percentage in the custom view. (later you can implement what are all the details you require from statusbarservice and send it back to your view using public exposed apis).

So i am going to expose a public function in MyStatusBarView class to get the battery percent and display it.
public void setBatteryLevel(int level);


public void updateBatteryStats(IconData batteryData)

In order for the framework compilation to pick up java files from 'mystatus' folder, add a entry in the file

/build/core/ as below.

1 - /build --> Add the folder.
$(addsuffix /java, \
core \
mystatus \
graphics \
location \
media \
opengl \
sax \
telephony \
wifi \
vpn \
keystore \

Resources usuage:

We might be interested in using resources ( like images, layouts) in status bar view. Include your resources in res folder. Now i have two questions for you

1 - We need to have file for compilation of java files in 'mystatus' (if in case if uses import com.mani.mystatus.R ).How we import these ?
2 - We need these resources to be brought to the devices. How we do this ?

For the first question

Include a entry in base/

This where framework-res R files are included before compilation.
(roughly line no 194 )

$(framework-res-source-path)/android/ \
$(framework-res-source-path)/android/ \
$(framework-res-source-path)/com/android/internal/ \

So we need to include our newly created file to this path.

mystatus-source-path := APPS/mystatus-res_intermediates/src

$(framework-res-source-path)/android/ \
$(framework-res-source-path)/android/ \
$(framework-res-source-path)/com/android/internal/ \

For second question

When files will be created ??. We need to compile the resources directory.
A resources directory will be compiled only if the compilation is for android application. ( i.e we need to create a apk out of it to see the file generated)

How do we make 'mystatus' a application. ( No activity is present but that is okay )
Keep a AndroidManifest.xml under a res folder and a '' file.


This manifest file basically tells the Resources will be under the package name 'com.mani.mystatus'

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)



LOCAL_PACKAGE_NAME := mystatus-res

# Install this alongside the libraries.

# Create package-export.apk, which other packages can use to get
# PRODUCT-agnostic resource data like IDs and type definitions.

include $(BUILD_PACKAGE) file is required for you to compile the subsystem from root directory.

For more understanding of android build process, what is going on when apk is built, please check below link.
# make mystatus-res (or) # make framework/base/mystatus/res/

'mystatus-res.apk' will be created and kept in

You need to push this apk also.

In order for the 'mystatus' folder to be compiled you need to compile the base.
mmm frameworks/base


framework.jar contains the dex files of 'mystatus' java files.

In order to compile the status bar service changes, compile the services part.
mmm frameworks/base/services/java


services.jar will have the changes/ recent modified changes in

So totally three files files needs to be pused the device.

adb -d remount
adb -d push out/target/product/generic/system/framework/services.jar /system/framework
adb -d push out/target/product/generic/system/framework/framework.jar /system/framework
adb -d push out/target/product/generic/system/framework/mystatus-res.apk /system/framework

For safer side, push the entire framework contents to your device.
adb -d push out/target/product/generic/system/framework/ /system/framework

So now when the system boots up, you would be seeing your own status bar view (MyStatusBarView).

Enjoy the work...!!

Snapshots for your reference:
This was tried out on vanilla android 2.2


  1. Hi Mani,
    I just tried out what you have posted, it works fine. I tried adding a icon on the fly on, placed the icon image in drawable of the mystatus/res/drawable , this compiles fine. When I try it on my device , it throws the below error

    'android.content.res.Resources$NotFoundException: Resource ID #0x7f020001
    E/AndroidRuntime( 1370): at android.content.res.Resources.getValue(
    E/AndroidRuntime( 1370): at android.content.res.Resources.getDrawable(
    E/AndroidRuntime( 1370): at android.view.View.setBackgroundResource(
    E/AndroidRuntime( 1370): at com.mist.customstatus.CustomStatusBarView.setVolumeLealarm_release: clear alarm, pending 0

    In framework/base/ , I have added path of the this new status bar file.

    Do you have any idea what could be going wrong?


  2. Hi...Kitty...!!

    The problem could be u might not have used the right 'context' instance to pick up the Resources.

    What i mean is,, you need to create a 'context' from the package where mystatus folder is present and use that context to inflate the view from mystatus-res.apk

    MystatusContext = context.createPackageContext("com.frameworks.mystatus", Context.CONTEXT_IGNORE_SECURITY);

    in mystatus-res.apk --> AndroidManifest.xml

    check what is the package name you have specified. Please use that package name and get a context and access the resources from this context. it should work fine.

    Any issues, pls revert back to me ..!!


  3. Hi Mani,

    I have not tried modifying Android source yet, can you please tell me, steps to build the modified source.

    Also tell me, whether we can test the modified source with emulator? if so, how to do it?


  4. Swathi..

    You can launch the emulator from AOSP (Source code) which can reflect the changes made ins status bar.

    For compiling source code.

    1 # . ./build/
    2 # lunch 1
    3 # make -j4

    Once the compilation is successfull (without any changes made) start making the changes as mentioned above and do "make -j4" again.

    Once it is successfull, go to

    You would see three img files created. system.img,boot.img,recover.img.

    Then launch the emulator as like this.
    #emulator -skin 1200x500.

    Now you would see the emualtor having the status bar changes.



  5. Hello,

    Your method is very usefull. I have create a complete moded status bar and he work fine on emulator.

    Now I want put it on galaxy tab! I have succed for services.odex and android.policy.odex with this method :

    Now I try to push mystatus-res.apk in tablet, but this create lots of errors about framework ressources. I think that it's signing problem, do you have an idea? Do you think that I could edit framework-res.apk?


  6. This is a beautiful post.
    It covers actually many concepts.
    Thnx :)

  7. @Anonymous:

    The method i was explaining will work on emulator or on the device which u are manufacturing and u have full access.. i mean root access..!!
    Coz u need to push the mystatus-res.apk into /system/app, which basically u cannot do in the other devices like Galaxy tab. Plus u need to replace the "services.jar" in the system. So this would be useful if you are having your own device and code base for it. (BSP).


  8. Thanks it's work. I have my custom status bar on rooted galaxy tab.


  9. Hi there,
    great post, thanks for it.

    I have little problem, i'm trying to achieve similar thing but in frameworks/opt. I've created there dir with my package name and done everything analogous.
    During compilation i got following error:

    error: cannot read: out/target/common/obj/APPS/xxx-xxx-res_intermediates/src/com/xxx/xxx/xxx/

    (changed to xxx because these're my client's private data)

    Do you maybe know what can cause it?

    Thank you

    $(framework-res-source-path)/android/ \
    $(framework-res-source-path)/android/ \

    You can remove this line,if you have this problem. I can help more if u can share the file.

  11. hi,
    how to implement back button in status bar?

  12. hi,
    while building android source code i am getting this error:out/target/common/obj/APPS/SystemUI_intermediates/src/com/android/systemui/ duplicate class:

    Even if I execute "rm" command to remove that file or execute "make clean".why is it so?
    I used the same command to build that you mentioned earlier.

  13. I am trying to add a new layout to the framework say my_layout.

    I succeeded partially in that .

    I defined my layout in an xml and put it inside frameworks/base/core/res/res/layout

    I then mentioned the id in frameworks/base/core/res/res/values public.xml and ids.xml

    And after performing a complete build :

    make framework

    make update-api


    i am able to access it as android.R.layout.my_layout

    But now i want to access it through xml also :Eg: "@android:layout/my_layout"

    In which place in the source do i mention this reference ?

    1. I resolved it ! I put the files into the sdk also !

  14. hey Maniii.

    i write code in my app

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
    ViewGroup.LayoutParams.WRAP_CONTENT, 30,
    | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
    lp.gravity = Gravity.CLIP_HORIZONTAL | Gravity.TOP;

    WindowManager wm = (WindowManager) getApplicationContext()
    wm.addView(view, lp);

    but it's give me an error
    "Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@416607a0 -- permission denied for this window type"

    and also having issue with import ""

    can you please help me i want to add one view in status bar but not notification

    thanks in advance :)

  15. Is it passible to do this in an APP on a non-rooted device? Thanks.

  16. In non-rooted device you cannot do this...!!

  17. Awesome.. Thanks for the directory structure explanation of the framework/base/*/com/*/ and it's registration in

  18. Hi I want to change position of system bar from bottom to top. can you please help on that.

  19. Could you send me that example to my mail id

  20. Could you explain how does the volume buttons are handled by the system? Where do I have to change if I have to change its UI (i.e. UI shown when there is a volume change)

  21. It seems possible to replace status bar on non-rooted devices. I don't know how but there are some apps on the market which add a specific status bar :

    Any idea ?

    1. Im looking for some piece of guide as what you re looking for.
      Not found yet :(

  22. hi mani is ur statusbar replaces android default status bar without rooting the device.

  23. hi mani,
    Is their any way to control hide and visible of status bar when we are ohter application like setting screen. Is thier any way to do that. Thanks

  24. Hi mani,

    I tried your method but its not only gives me following error when i try to compile using command make make framework/base/mystatus/res/ .

    Please help...

    find: `out/target/common/docs/gen': No such file or directory
    build/core/ *** frameworks/base/mystatus/res: Target java module does not define any source or resource files. Stop.

  25. Hi Mani,

    I am trying to modify the Statusbar and Navigation Bar height by modifying
    frameworks/base/core/res/res/values/dimens.xml in Android 6.0 AOSP code. I have a rooted device as well. I build and replaced the service.jar , framework.jar and ext.jar in the system/framework folder of my device. But the height is not changing. I replaced the SystemUI.apk as well. Any help is appreciated.

    name="status_bar_height" as 84dp

    name="navigation_bar_height" as 148dp


  26. I simply want to say I’m very new to blogs and actually loved you’re blog site. Almost certainly I’m going to bookmark your blog post . You absolutely come with great well written articles. Thanks a lot for sharing your blog.
    Android training in chennai with placement | Android Training in chennai |Android Training in Velachery

  27. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this development course fees in chennai | android app development training in chennai