title: Android set full screen from fragment
body: <p>This is my question: I have an android app which allows users to go full screen for a better readability. The full screen fab toggle button is placed inside a fragment which actually contains the readings.</p>
  <p>To make it dead simple:</p>
  <ul>
  <li>Main Activity contains Readings Fragment</li>
  <li>Readings Fragment contains a fab button to toggle full screen</li>
  </ul>
  <p>To trigger the full screen I use this snippet:</p>
  <pre><code>this.fullScreenFab.setOnClickListener(v -&gt; {
      WindowManager.LayoutParams attrs = getActivity().getWindow().getAttributes();
      if (this.isFullScreen) {
          this.isFullScreen = false;
          ((AppCompatActivity) 
  getActivity()).getSupportActionBar().show();
      getActivity().getWindow().getDecorView().setSystemUiVisibility(
              View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                      | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                      | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
  
  } else {
      this.isFullScreen = true;
      ((AppCompatActivity) getActivity()).getSupportActionBar().hide();
      getActivity().getWindow().getDecorView().setSystemUiVisibility(
              View.SYSTEM_UI_FLAG_LOW_PROFILE
                      | View.SYSTEM_UI_FLAG_FULLSCREEN
                      | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                      | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                      | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                      | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
  
  }
  getActivity().getWindow().setAttributes(attrs);
  });
  </code></pre>
  <p>Now, it works well, except that the status bar and action bar spaces keep showing. The activity goes FS (even Android warn me of this) but the space  occupied by those two elements remain.</p>
  <p><strong>Full screen disabled:</strong></p>
  <p><a href="https://i.stack.imgur.com/XCw3o.png" rel="noreferrer"><img src="https://i.stack.imgur.com/XCw3o.png" alt="enter image description here" /></a></p>
  <p><strong>Full screen enabled:</strong></p>
  <p><a href="https://i.stack.imgur.com/UA92R.png" rel="noreferrer"><img src="https://i.stack.imgur.com/UA92R.png" alt="enter image description here" /></a></p>
  <p>As you can see, the FS one has the top and bottom occupied, so the fragment does not go for a real full screen.</p>
  <p>Fragment has the</p>
  <pre><code>android:fitsSystemWindows=&quot;true&quot;
  </code></pre>
  <p>Send help please!
  Thanks in advance.
  Valerio</p>