美文网首页Android 工具类
StatusBarUtil 状态栏 和 NavigationBa

StatusBarUtil 状态栏 和 NavigationBa

作者: 苍天霸气诀 | 来源:发表于2017-10-19 17:36 被阅读0次
     //获取是否存在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;
        }

    相关文章

      网友评论

        本文标题:StatusBarUtil 状态栏 和 NavigationBa

        本文链接:https://www.haomeiwen.com/subject/bmhpuxtx.html