//获取是否存在NavigationBar
public static boolean checkDeviceHasNavigationBar(Context context) {
boolean hasNavigationBar = false;
Resources rs = context.getResources();
int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
if (id > 0) {
hasNavigationBar = rs.getBoolean(id);
}
try {
Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
Method m = systemPropertiesClass.getMethod("get", String.class);
String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
if ("1".equals(navBarOverride)) {
hasNavigationBar = false;
} else if ("0".equals(navBarOverride)) {
hasNavigationBar = true;
}
} catch (Exception e) {
}
return hasNavigationBar;
}
// 获取tNavigationBar高度
public static int getNavigationBarHeight(Activity activity) {
int height=0;
if(checkDeviceHasNavigationBar(activity)){
Resources resources = activity.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height","dimen", "android");
height= resources.getDimensionPixelSize(resourceId);
}
return height;
}
// 获取状态栏高度
public static int getStatusBarHeight(Activity activity) {
int height = 0;
int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen",
"android");
if (resourceId > 0) {
height = activity.getResources().getDimensionPixelSize(resourceId);
}
return height;
}
网友评论