title: open a fragment from viewpager fragment
body: <p>I have a TabLayout with viewpager. The TabLayout has 3 tabs which means there are 3 fragments. I want to open a new fragment from one of the fragment in such a way that the layout of the new fragment covers the Tabs also(i.e. whole screen). Right now the tabs are not covered as we are opening fragment from viewpager.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>Activity:
  
  public class ContainerActivity extends AppCompatActivity {
      private ViewPager viewPager;
      private FragmentPagerAdapter pagerAdapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_contain);
  
          TabLayout tabs = (TabLayout)findViewById(R.id.tabs);
          viewPager = (ViewPager) findViewById(R.id.pagerFragments);
  
          pagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
          viewPager.setAdapter(pagerAdapter);
          tabs.setupWithViewPager(viewPager);
          tabs.setTabTextColors(ContextCompat.getColorStateList(getApplicationContext(), R.drawable.tab_text_color));
          tabs.setSelectedTabIndicatorColor(ContextCompat.getColor(getApplicationContext(), R.color.strip_ind));
      }
  
      @Override
      public void onBackPressed() {
          FragmentManager fm = getSupportFragmentManager();
          if (fm.getBackStackEntryCount() &gt; 0) {
              fm.popBackStack();
              return;
          } else {
              Fragment currFragment = fm.findFragmentByTag("android:switcher:" + viewPager.getId() +
                      ":" + pagerAdapter.getItemId(viewPager.getCurrentItem()));
              if (currFragment != null) {
                  FragmentManager cfm = currFragment.getChildFragmentManager();
                  if (cfm.getBackStackEntryCount() &gt; 0) {
                      cfm.popBackStack();
                      return;
                  }
              }
          }
  
          super.onBackPressed();
      }
  
      private  class MyPagerAdapter extends FragmentPagerAdapter {
  
          private  String[] pages;
  
          public MyPagerAdapter(FragmentManager fm) {
              super(fm);
              pages = getResources().getStringArray(R.array.nav_tabs);
          }
  
          @Override
          public CharSequence getPageTitle(int position) {
              return pages[position];
          }
  
          @Override
          public Fragment getItem(int position) {
              switch (position){
                  case 0:
                      return new GalleryFragment();
                  case 1:
                      return new PhotoFragment();
                  case 2:
                      return new VideoFragment();
              }
              return null;
          }
  
          @Override
          public int getCount() {
              return pages.length;
          }
      }
  
      public void returnPhotoUri(Uri uri) {
          Intent data = new Intent();
          data.setData(uri);
  
          if (getParent() == null) {
              setResult(RESULT_OK, data);
          } else {
              getParent().setResult(RESULT_OK, data);
          }
  
          finish();
      }
  
      public void onCancel(View view) {
          getSupportFragmentManager().popBackStack();
      }
  
  
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>Fragment of ViewPager:
  
  public class VideoFragment extends Fragment{
  
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View v = inflater.inflate(R.layout.videofrag, container, false);
  
          Button record = (Button)v.findViewById(R.id.record);
          record.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                      Fragment fragment = new FilterFragment();
              getChildFragmentManager().beginTransaction()
                      .replace(R.id.filter_fragment, fragment)
                      .addToBackStack(null)
                      .commit(); 
              }
          });
          return v;
      }
  }</code></pre>
  </div>
  </div>
  </p>