I've got the problem that I need the height of the android tablet system bar. It's the same problem as over here, but I cant use this answer, because it gives me the same size as from the DisplayMetrics. At both ways I get the resolution with this bar allready calculated in it. (This problem doesnt appear at my smartphone, just on my tablet).
Asked
Active
Viewed 6,609 times
3 Answers
11
// status bar (at the top of the screen on a Nexus device)
public static int getStatusBarHeight(Context context) {
Resources resources = context.getResources();
int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
return resources.getDimensionPixelSize(resourceId);
}
return 0;
}
// navigation bar (at the bottom of the screen on a Nexus device)
public static int getNavigationBarHeight(Context context) {
Resources resources = context.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
return resources.getDimensionPixelSize(resourceId);
}
return 0;
}

Chris Lacy
- 4,222
- 3
- 35
- 33
-
both your methods are exactly the same – Frank Nov 20 '13 at 13:55
-
2@Frank - Different values are passed as the first argument to `getIdentifier()`. – Chris Lacy Nov 20 '13 at 20:26
0
Check out this answer here: https://stackoverflow.com/a/8367739/807499
It gives the full height of the screen. You can then minus the size given by DisplayMetrics or by your root layout's size.

Community
- 1
- 1

David Scott
- 1,666
- 12
- 22
0
Chris Banes mentioned this in a recent Droidcon talk. The whole talk is super relevant, but here's a link to the part that answers your question (for all form factors, including tablet).
https://youtu.be/_mGDMVRO3iE?t=1093
This is the correct way to get status bar and navigation bar sizes: setOnApplyWindowListener
I hope this helps!

keith
- 3,105
- 2
- 29
- 34