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)
To solve this, I used a combination approach. This is necessary as on tablets the system bar already subtracts it's pixels when display.getHeight() is called. So I first check if a system bar is present, and then Ben Claytons approach, which works fine on phones.
The default height used to be 25dp. With Android Marshmallow (API 23) the height was reduced to 24dp.
Try this:
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
According to Google design guidelines; height of status bar is 24 dp.
If you want get status bar height in pixels you can use below method:
which can be called from activity with:
Hardcoding the size or using reflection to get the value of
status_bar_height
is considered bad practice. Chris Banes talked about this in at the Droidcon New York. The recommended way of getting the status bar size is via the OnApplyWindowInsetsListener:This was added in API 20 and is also backported via ViewAppCompat.