Android获取statusBar和navigationBar高度

Resources resources = mContext.getResources();

int resIdStatusbarHeight = resources.getIdentifier("status_bar_height", "dimen", "android");

int statusBarHeight = 0;
if(resIdStatusbarHeight > 0){
statusBarHeight = resources.getDimensionPixelSize(resIdStatusbarHeight);//状态栏高度
}


int resIdShow = resources.getIdentifier("config_showNavigationBar", "bool", "android");
boolean hasNavigationBar = false;
if(resIdShow > 0){
hsNavigationBar = resources.getBoolean(resIdShow);//是否显示底部navigationBar
}
if(hasNavigationBar){
int resIdNavigationBar = resources.getIdentifier("navigation_bar_height", "dimen", "android");
int navigationbarHeight = 0;
if(resIdNavigationBar > 0){

navigationbarHeight = resources.getDimensionPixelSize(resIdNavigationBar);//navigationBar高度

}

}

你可能感兴趣的:(Android开发基础)