• 21天学习挑战赛--第二天打卡(setSystemUiVisibility、导航栏、状态栏)


    1.setSystemUiVisibility(int visibility)

    通过setSystemUiVisibility(int visibility)方法,可以改变状态栏或者其他系统UI的可见性。

    getWindow().getDecorView().setSystemUiVisibility(int visibility);

    可供选择的参数:

    ①View.SYSTEM_UI_FLAG_VISIBLE

    默认模式,显示状态栏和导航栏

    ②View.SYSTEM_UI_FLAG_LOW_PROFILE

    低调模式,隐藏不重要的状态栏图标,导航栏中相应的图标都变成了一个小点。点击状态栏或导航栏还原成正常的状态。

    ③SYSTEM_UI_FLAG_HIDE_NAVIGATION

    隐藏导航栏,点击屏幕任意区域,导航栏将重新出现,并且不会自动消失。

    ④SYSTEM_UI_FLAG_FULLSCREEN

    隐藏状态栏,点击屏幕区域不会出现,需要从状态栏位置下拉才会出现。

    ⑤SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

    将布局内容拓展到导航栏和状态栏的后面。

     

    2.获取状态栏、导航栏高度

    ①获取顶部状态栏statusBar高度

    private int getStatusBarHeight() {

        Resources resources = mActivity.getResources();

        int resourceId = resources.getIdentifier( "status_bar_height", "dimen","android");

        int height = resources.getDimensionPixelSize( resourceId);

        Log.v("", "Status height:" + height);

        return height;

    }

    ②获取底部导航栏navigationBar高度

    private int getNavigationBarHeight() {

        Resources resources = mActivity.getResources();

        int resourceId = resources.getIdentifier( "navigation_bar_height","dimen", "android");

        int height = resources.getDimensionPixelSize( resourceId);

        Log.v("", "Navi height:" + height);

        return height;

    }

    ③获取设备是否存在NavigationBar

    public static boolean checkHasNavigationBar( 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;

    }

    注:没显示导航栏的,方法二还是会返回导航栏的值,而不是返回0,所以要结合方法三使用

     

  • 相关阅读:
    深度学习第一次作业 - 波士顿房价预测
    UE4 获取HTTP接口数据 (UE4与python通信)
    web大作业:基于html+css+javascript+jquery实现智能分控网站
    相控阵天线(八):圆环阵列天线和球面阵列天线
    HTML之MIME type
    纯js实现录屏并保存视频到本地的尝试
    【100天精通Python】Day70:Python可视化_绘制不同类型的雷达图,示例+代码
    Flask 学习-48.Flask-RESTX 使用api.model() 模型工厂
    使用 Sa-Token 实现 [记住我] 模式登录、七天免登录
    JavaScript和TypeScript的特点
  • 原文地址:https://blog.csdn.net/zenmela2011/article/details/126146396