title: Make fragments full screen programmatically
body: <p>I have a ViewPager and FragmentPagerAdapter set up in one activity with 3 fragments. All fragments are loaded simultaneously and are kept in memory using</p>
  
  <pre><code>mPager.setOffscreenPageLimit(2);
  </code></pre>
  
  <p>One of these fragments hosts a camera preview that I would like to make full screen, with no status bar or action bar. The other fragments require that the action bar be displayed.</p>
  
  <p>How would I make only the camera preview fragment full screen while keeping the other two fragments normal? I have tried using themes, which means breaking the action bar. </p>
  
  <p>Programmatically calling the following doesn't help, because it forces the whole activity to be full screen (and thus the other two fragments along with it):</p>
  
  <pre><code>requestWindowFeature(Window.FEATURE_NO_TITLE); 
  this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  setContentView(R.layout.main);
  </code></pre>
  
  <p>I also tried implementing ViewPager.OnPageChangeListener:</p>
  
  <pre><code>public void onPageSelected(int position) {
      if(position == 1)
          getActionBar().hide();
      else
          getActionBar().show();
  }
  </code></pre>
  
  <p>This does hide the action bar, but it doesn't hide the system status bar (I'm talking about where the notifications, status icons, and time are), and the action bar hide/show animation is also very choppy when swiping.</p>
  
  <p>For an example of what I want to do exactly, see Snapchat - they manage to pull off the swiping between camera and other fragments perfectly.</p>
  
  <p>Edit:</p>
  
  <p>So I changed my onPageSelected to this:</p>
  
  <pre><code>public void onPageSelected(int position) {
      if(position == 1) {
          MainActivity.this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
          MainActivity.this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
      } else {
          MainActivity.this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
          MainActivity.this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
      }
  }
  </code></pre>
  
  <p>This enables me to change whether the status bar is displayed or not. However, it causes a large amount of jank. Same problem with the action bar.</p>
  
  <p>I notice that in Snapchat the status bar slides up and down after the tab change is complete. I'm not sure how to implement this, so any advice regarding this aspect would be appreciated.</p>