获取状态栏高度
public static int getStatusHeight(Context context) {
int status_bar_height = 0;
int h = context.getResources().getDimensionPixelSize(
context.getResources().getIdentifier("status_bar_height", "dimen", "android"));
if(h > 0){
status_bar_height = h;
}
return status_bar_height;
}
获取导航栏高度
public static int getNavBarHeight(Context context, boolean islandscape) {
int navBarHeight = 0;
if (!ViewConfiguration.get(context).hasPermanentMenuKey()) {
String name = "navigation_bar_height";
if (islandscape) {
name = "navigation_bar_height_landscape";
}
navBarHeight = context.getResources().getDimensionPixelSize(
context.getResources().getIdentifier(name, "dimen", "android"));
}
return navBarHeight;
}