判断是否手机是否有导航栏

private boolean hasNavigationBar() {
        Display display = getWindowManager().getDefaultDisplay();
        DisplayMetrics displayMetrics = new DisplayMetrics();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            // 获取设备的硬件屏幕高度
            display.getRealMetrics(displayMetrics);
            int realHeightPixels = displayMetrics.heightPixels;
            int realWidthPixels = displayMetrics.widthPixels;

            // 内容区域的屏幕高度
            displayMetrics = new DisplayMetrics();
            display.getMetrics(displayMetrics);
            int heightPixels = displayMetrics.heightPixels;
            int widthPixels = displayMetrics.widthPixels;

            int dHight = realHeightPixels - heightPixels;
            int dWidth = realWidthPixels - widthPixels;
            return dHight > 0 || dWidth > 0;
        }
        return false;
    }

 

posted on 2017-06-06 15:48  LoaderMan  阅读(306)  评论(0编辑  收藏  举报

导航