Android: show/hide status bar/power bar

后端 未结 9 1147
梦如初夏
梦如初夏 2020-12-07 20:03

I am trying to create a button where I can hide or show the status bar on my tablet.

I\'ve put in the onCreate

getWindow().addFlags(WindowManager.Lay         


        
9条回答
  •  温柔的废话
    2020-12-07 21:08

    I've tried so many things.

    Finally, It is the most suitable code to hide and show full screen mode.

    private fun hideSystemUi() {
    
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            window.setDecorFitsSystemWindows(true)
        } else {
            // hide status bar
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            window.decorView.systemUiVisibility =
                View.SYSTEM_UI_FLAG_IMMERSIVE or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        }
    
    }
    
    private fun showSystemUi() {
    
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            window.setDecorFitsSystemWindows(false)
        } else {
            // Show status bar
            window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            window.decorView.systemUiVisibility = SYSTEM_UI_FLAG_LAYOUT_STABLE
        }
    
    }
    

    It Implemented it in this app : Android Breakdown.

    Go to Videos(Bottom Bar) > Play Any Video > Toggle Fullscreen

提交回复
热议问题