美文网首页Android知识程序员
分享两个效果 - Android 系统 UI 管理

分享两个效果 - Android 系统 UI 管理

作者: Passon_Fang | 来源:发表于2017-10-30 23:41 被阅读66次
    SystemUIManage.gif

    系统 UI 管理,官方 Train

    Dimming the System Bars (沉浸模式)

    知乎 和 Medium 中都使用到了这个效果,作为沉浸式阅读模式。

    // This example uses decor view, but you can use any visible view.
    View decorView = getWindow().getDecorView();
    int uiOptions = View.SYSTEM_UI_FLAG_LOW_PROFILE;
    decorView.setSystemUiVisibility(uiOptions);
    

    Reveal the Status and Navigation Bars (全屏模式)

        public void toggleHideyBar() {
    
            // BEGIN_INCLUDE (get_current_ui_flags)
            // The UI options currently enabled are represented by a bitfield.
            // getSystemUiVisibility() gives us that bitfield.
            int uiOptions = getWindow().getDecorView().getSystemUiVisibility();
            int newUiOptions = uiOptions;
            // END_INCLUDE (get_current_ui_flags)
            // BEGIN_INCLUDE (toggle_ui_flags)
            boolean isImmersiveModeEnabled =
                    ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
            if (isImmersiveModeEnabled) {
                Log.i("SystemUI", "Turning immersive mode mode off. ");
            } else {
                Log.i("SystemUI", "Turning immersive mode mode on.");
            }
    
            // Navigation bar hiding:  Backwards compatible to ICS.
            if (Build.VERSION.SDK_INT >= 14) {
                newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
            }
    
            // Status bar hiding: Backwards compatible to Jellybean
            if (Build.VERSION.SDK_INT >= 16) {
                newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
            }
    
            // Immersive mode: Backward compatible to KitKat.
            // Note that this flag doesn't do anything by itself, it only augments the behavior
            // of HIDE_NAVIGATION and FLAG_FULLSCREEN.  For the purposes of this sample
            // all three flags are being toggled together.
            // Note that there are two immersive mode UI flags, one of which is referred to as "sticky".
            // Sticky immersive mode differs in that it makes the navigation and status bars
            // semi-transparent, and the UI flag does not get cleared when the user interacts with
            // the screen.
            if (Build.VERSION.SDK_INT >= 18) {
                newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
            }
    
            getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
            //END_INCLUDE (set_ui_flags)
        }
    

    相关文章

      网友评论

        本文标题:分享两个效果 - Android 系统 UI 管理

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