0

I found out how I can hide the navigation with this

View decorView = getWindow().getDecorView();
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                if (visibility == 0){
                    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
                }
            }
        });
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if(hasFocus){
            decorView.setSystemUiVisibility(hideSystemBars());
        }
    }

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    private int hideSystemBars(){
        return View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    }

It works for that activity. I'm developing an app right now and already have plenty of activities. Is there a way how to set this for all activities or do I have to put this snippet in all of my activity?

Takuya2412
  • 187
  • 10
  • 1
    you can make some BaseActivity for your poject or shared library with the code above and inherit all your activites from it. – While True Apr 07 '20 at 17:48
  • But how? I tried to make another Helper class and put the code there and try to call it with the constructor.. not worked.. how can I make a BaseActivity and inherit them? All my activities inherit from AppCompat already – Takuya2412 Apr 07 '20 at 17:53
  • 1
    You make `class BaseActivity extends AppCompatActivity`. Then you override `onWindowFocusChanged` method as you wrote. Then I guess you override `onCreate` where you put `setOnSystemUiVisibilityChangeListener` and then `class YourActivity extends BaseActivity`. – While True Apr 07 '20 at 18:01
  • have you managed to do that?) – While True Apr 15 '20 at 12:09
  • Yep! I made a BaseActivity class which extends AppCompatActivity and override onCreate as you said! Thank you – Takuya2412 Apr 16 '20 at 13:52

0 Answers0