Android statusbar overlay with ActionBar

后端 未结 4 789
猫巷女王i
猫巷女王i 2021-02-07 03:39

I know that I can make the ActionBar overlay using requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY)
and can toggle/show the status bar in my screen (by switch

4条回答
  •  我在风中等你
    2021-02-07 04:22

    It's not perfect, but this is how I have achieved what you want:

    In onCreate:

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

    Then:

    private void hideStatusBar() {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
    
    }
    
    private void showStatusBar() {
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
    }
    

    I also have a style on the activity with the following:

      
    

    Your activity will shift down when the status bar shows, but I don't think it's too noticeable.

提交回复
热议问题