0

I'm building an app for Android (6.0, but I can change it if necessary), and having trouble getting the status and navigation bars to hide properly. I've followed every online suggestion I can find, but the two bars both hide properly whenever the app is launched or resumed, but they instantly reappear whenever I tap. I've added the following code to styles.xml:

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name = "android:windowActionBar">false</item>
        <item name = "android:windowNoTitle">true</item>
    </style>

And in MainActivity.java:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        hideBars();
    }
    @Override
    public void onResume(){
        super.onResume();
        hideBars();
    }
    void hideBars(){
        setContentView(R.layout.activity_main);

        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
        ActionBar actionBar = getSupportActionBar();
        actionBar.hide();
    }

How can I get the two bars to go away permanently without immediately reappearing when I tap?

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
Bagelman
  • 766
  • 8
  • 14

2 Answers2

0

NoActionBar should solve your problem.

<style name=“AppTheme” parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name = "android:windowActionBar">false</item>
    <item name = "android:windowNoTitle">true</item>
</style>
Kshitij Saxena
  • 930
  • 8
  • 19
  • Thanks for your answer. Unfortunately, this doesn't fix the issue of the action bar reappearing every time I tap within the app window. – Bagelman Mar 23 '19 at 18:50
0

Okay, so I figured out what was wrong. In order to prevent the bars from reappearing after tapping, the View.SYSTEM_UI_FLAG_IMMERSIVE flag has to be set. This makes it so that the action bar only reappears when users swipe from the edges of the screen.

Bagelman
  • 766
  • 8
  • 14