Answer the question
In order to leave comments, you need to log in
How to display nested fragment after return?
There is a main activity MainActivity , in which the framelayout is located
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/mainContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/navigationContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/tabLayout" />
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
style="@style/AppTabLayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentBottom="true"
android:background="#FFFFFF"
android:elevation="@dimen/size_medium"
tools:targetApi="lollipop">
<android.support.design.widget.TabItem
android:layout_width="@dimen/size_large"
android:layout_height="@dimen/size_large"
android:icon="@drawable/ic_nav_main" />
<android.support.design.widget.TabItem
android:layout_width="@dimen/size_large"
android:layout_height="@dimen/size_large"
android:icon="@drawable/ic_nav_popular" />
<android.support.design.widget.TabItem
android:layout_width="@dimen/size_large"
android:layout_height="@dimen/size_large"
android:icon="@drawable/ic_nav_favorites" />
</android.support.design.widget.TabLayout>
</RelativeLayout>
val transaction = fragmentManager?.beginTransaction()
transaction?.replace(R.id.navigationContainer, fragment, screenKey)
?.addToBackStack(screenKey)?.commit()
val transaction = fragmentManager?.beginTransaction()
transaction?.replace(R.id.mainContainer fragment, screenKey)
?.addToBackStack(screenKey)?.commit()
Answer the question
In order to leave comments, you need to log in
In order for this to work correctly, nested fragments (those added to R.id.navigationContainer) need to be added not through the main FragmentManager, but through the ChildFragmentManager, which can be obtained from the fragment.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question