Android: show/hide status bar/power bar

后端 未结 9 1133
梦如初夏
梦如初夏 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 20:43

    Reference - https://developer.android.com/training/system-ui/immersive.html

    // This snippet shows the system bars. It does this by removing all the flags
    // except for the ones that make the content appear under the system bars.
    private void showSystemUI() {
        mDecorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }
    
    0 讨论(0)
  • 2020-12-07 20:48

    For Kotlin users

    TO SHOW

    activity?.window?.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)

    TO HIDE

    activity?.window?.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)

    0 讨论(0)
  • 2020-12-07 20:50

    with this method, using SYSTEM_UI_FLAG_IMMERSIVE_STICKY the full screen come back with one tap without any implementation. Just copy past this method below and call it where you want in your activity. More details here

    private void hideSystemUI() {
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_IMMERSIVE
                        // Set the content to appear under the system bars so that the
                        // content doesn't resize when the system bars hide and show.
                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        // Hide the nav bar and status bar
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN);
    }
    
    0 讨论(0)
  • 2020-12-07 20:50
    fun Activity.setStatusBarVisibility(isVisible: Boolean) {
        //see details https://developer.android.com/training/system-ui/immersive
        if (isVisible) {
            window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
            window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
        } else {
            window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    or View.SYSTEM_UI_FLAG_FULLSCREEN)
        }
    }
    
    0 讨论(0)
  • 2020-12-07 20:53

    used for kolin in android for hide status bar in kolin no need to used semicolon(;) at the end of the line

    window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
    

    in android using java language for hid status bar

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
    0 讨论(0)
  • 2020-12-07 20:58
     @Override
     protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //hide status bar
        requestWindowFeature( Window.FEATURE_NO_TITLE );
        getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN );
    
    
        setContentView(R.layout.activity_main);
    }
    
    0 讨论(0)
提交回复
热议问题