• 怎么准确的判断当前页面是否有虚拟导航栏


        /**
         *
         * @return
         */
        public boolean phoneHasNav(){
            boolean flag = false;
    
            if(Build.VERSION.SDK_INT < 14){
                flag = false;
            }else {
                View content = getWindow().getDecorView().findViewById(android.R.id.content);
                if (content != null) {
                    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
                    Display display = wm.getDefaultDisplay();
                    Point point = new Point();
                    display.getRealSize(point);
    
                    if (isScreenPortrait()) {
                        int bottom = content.getBottom();// 页面的底部
                        if (bottom != point.y) {
                            flag = true;
                        }
                    }else {
                        int right = content.getRight();
                        if (right != point.y) {
                            flag = true;
                        }
                    }
                }
            }
            return flag;
        }
    
    
        /** 获取屏幕是否是竖屏
         * @return
         */
        @SuppressLint("SwitchIntDef")
        public boolean isScreenPortrait(){
            int or = getRequestedOrientation();
            switch (or) {
                case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE :// 横屏
                case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
                    return false;
                case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT :// 竖屏
                case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
                    return true;
                default:
                    return true;
            }
        }

    这个是很精确地,写在Activity里面就可以使用了。原来是根据当前页面的底部和屏幕真实的高度做判断。很精确。我自己发明的。真的是,自己想的办法。卧槽。根据布局自己一点一点的试出来的。

  • 相关阅读:
    计算机知识
    试题:论需求分析方法及应用
    试题:论信息系统开发方法及应用
    爬虫数据存储——安装docker和ElasticSearch(基于Centos7)
    go并发版爬虫
    go单任务版爬虫
    可变类型与不可变类型
    基本数据类型内置方法
    @submit.native.prevent作用
    获取当月第一天,今天的日期的方法
  • 原文地址:https://www.cnblogs.com/caoxinyu/p/10568559.html
Copyright © 2020-2023  润新知