Height of status bar in Android

2018-12-31 15:29发布

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)

20条回答
裙下三千臣
2楼-- · 2018-12-31 16:06

Toggled Fullscreen Solution:

This solution may look like a workaround, but it actually accounts for whether your app is fullscreen (aka hiding the status bar) or not:

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point(); display.getSize(size);
int barheight = size.y - findViewById(R.id.rootView).getHeight();

This way, if your app is currently fullscreen, barheight will equal 0.

Personally I had to use this to correct absolute TouchEvent coordinates to account for the status bar as so:

@Override
public boolean onTouch(View view,MotionEvent event) {
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point(); display.getSize(size);
    int YCoord = (int)event.getRawY() - size.y + rootView.getHeight());
}

And that will get the absolute y-coordinate whether the app be fullscreen or not.

Enjoy

查看更多
临风纵饮
3楼-- · 2018-12-31 16:09

Official height is 24dp, as is stated officially by Google on Android Design webpage.

查看更多
登录 后发表回答