![[Android] 获取系统顶部状态栏(Status Bar)与底部导航栏(Navigation Bar)的高度 [Android] 获取系统顶部状态栏(Status Bar)与底部导航栏(Navigation Bar)的高度](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
Android一些设备都有上下两条bar,我们可以获取这些bar的信息。下面放上获取高度的代码。代码注释和其他方法有空再放。
原文地址请保留http://www.cnblogs.com/rossoneri/p/4142962.html
获取顶部status bar 高度
private int getStatusBarHeight() {
Resources resources = mActivity.getResources();
int resourceId = resources.getIdentifier("status_bar_height", "dimen","android");
int height = resources.getDimensionPixelSize(resourceId);
Log.v("dbw", "Status height:" + height);
return height;
}
获取底部 navigation bar 高度
private int getNavigationBarHeight() {
Resources resources = mActivity.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height","dimen", "android");
int height = resources.getDimensionPixelSize(resourceId);
Log.v("dbw", "Navi height:" + height);
return height;
}