So I have implemented Tab layout with ViewPager in my app. Each tab shows a fragment. Now I want to open a new fragment(lets call it B) from one of these fragments in the tab layout(lets call it A). So A is in tab layout but I want B to take up whole screen. I am even able to do it but I am facing little problem. The new fragment doesn't take up the whole screen. Instead it just replaces the previous fragment, and it looks like it was a part of the tab layout.
This is the layout of the fragment A (from which I launch the new fragment).
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/parent">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="0dp" />
</FrameLayout>
</LinearLayout>
In the class of fragment A, I launch new fragment using theses lines,
Bundle bundle = new Bundle();
FragmentTransaction fragmentTransaction = getActivity()
.getSupportFragmentManager()
.beginTransaction();
Fragment fragmentB = new FragmentB();
fragmentB.setArguments(bundle);
fragmentTransaction.replace(R.id.parent, fragmentB);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
Also my main activity, the one that these fragments are attached to implements tavLayout using viewPager.
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@id/tab_layout"/>
I end up seeing a new fragment (the fragment B) but as a part of the Tab Layout while I want to hide the tab layout. Please help me, I went through many SO questions but I felt that I am doing some thing wrong as they didn't work for me. Thanks !!