美文网首页
获取全面屏手机高度

获取全面屏手机高度

作者: AndyLuo2018 | 来源:发表于2019-07-06 16:39 被阅读0次
    public class FullScreenManager {
    
        /**
         * 获取状态栏高度
         * @param activity
         * @return
         */
        public static int getStatusBarHeight(Activity activity) {
            Resources resources = activity.getResources();
            int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
            int height = resources.getDimensionPixelSize(resourceId);
            return height;
        }
    
        /**
         * 获取底部虚拟导航栏高度
         * @param activity
         * @return
         */
        public static int getNavigationBarHeight(Activity activity) {
            Resources resources = activity.getResources();
            int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
            int height = resources.getDimensionPixelSize(resourceId);
            return height;
        }
    
        /**
         * 非全面屏下 虚拟按键是否打开
         * @param activity
         * @return
         */
        public static boolean isNavigationBarShown(Activity activity){
            //虚拟键的view,为空或者不可见时是隐藏状态
            View view  = activity.findViewById(android.R.id.navigationBarBackground);
            if(view == null){
                return false;
            }
            int visible = view.getVisibility();
            if(visible == View.GONE || visible == View.INVISIBLE){
                return false ;
            }else{
                return true;
            }
        }
    }
    
    

    相关文章

      网友评论

          本文标题:获取全面屏手机高度

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