[Code block] Immersive interface

The top status bar and bottom navigation bar will not occupy the display controls, and will be hidden after the interface gains focus

JAVA

/**
     * 沉浸式页面
     *
     * @param hasFocus 焦点
     */
    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
    
    
        super.onWindowFocusChanged(hasFocus);
        View decorView = getWindow().getDecorView();
        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
        );
        getWindow().setStatusBarColor(Color.TRANSPARENT);//某些弹窗弹出会导致状态栏闪烁,透明处理解决
        getWindow().setNavigationBarColor(Color.TRANSPARENT);
    }

Kotlin

/**
 * 沉浸式页面
 *
 * @param hasFocus 焦点
 */
override fun onWindowFocusChanged(hasFocus: Boolean) {
    
    
    super.onWindowFocusChanged(hasFocus)
    if (hasFocus) {
    
    
        window.run {
    
    
            decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    or View.SYSTEM_UI_FLAG_FULLSCREEN)
            //某些弹窗弹出会导致状态栏闪烁,透明处理解决
            statusBarColor = Color.TRANSPARENT 
            navigationBarColor = Color.TRANSPARENT
        }
    }
}

Guess you like

Origin blog.csdn.net/qq_36881363/article/details/105160950