views:

849

answers:

4

What's the height of the status bar in Android? Is it always the same?

From my measurements it seems that it's 25dp, but I'm not sure if it has the same height on all platforms.

(I want to know this to properly implement a fade transition from an activity that doesn't have status bar to one that does)

+1  A: 

Try this:

    Rect rect = new Rect();
    Window win = this.getWindow();
    win.getDecorView().getWindowVisibleDisplayFrame(rect);
    int statusBarHeight = rect.top;
    int contentViewTop = win.findViewById(Window.ID_ANDROID_CONTENT).getTop();
    int titleBarHeight = contentViewTop - statusBarHeight;
    Log.d("ID-ANDROID-CONTENT", "titleBarHeight = " + titleBarHeight );

it didn't work for me in the onCreate method for the activity, but did when I put it in an onClickListener and gave me a measurement of 25

Martyn
+1  A: 

this question was answered before... http://stackoverflow.com/questions/3355367/height-of-statusbar/3356263#3356263

Update:: ok, the height of the status bar depends on the screen size, for example in a device with 320 X 480 screen size the status bar height is 25px, for a device with 480 x 800 the status bar height must be 38px

so i recommed to use this script to get the status bar height

Rect rectgle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int StatusBarHeight= rectgle.top;
int contentViewTop= 
    window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int TitleBarHeight= contentViewTop - StatusBarHeight;

   Log.i("*** Jorgesys :: ", "StatusBar Height= " + StatusBarHeight + " , TitleBar Height = " + TitleBarHeight); 
Jorgesys
Not exactly. I'm also asking if I can assume that the status bar has the same height in all devices.
hgpc
nop! you have to get the value of the heigth
Jorgesys
Or use dip? If it always has 25dip then the code is not needed.
hgpc
A: 

i agree Martyn "it didn't work for me in the onCreate method for the activity, but did when I put it in an onClickListener and gave me a measurement of 25 " i meet the same things.

pengwang
A: 

If you know exactly the size VS height

like

for example in a device with 320 X 480 screen size the status bar height is 25px, for a device with 480 x 800 the status bar height must be 38px

then you can just get the width of your view / the screen size you can just use an if else statement to get the height of status bar

Steven Shih