Reputation: 319
bottomnavigation not change fragment when i click, it work on activity but when i use it in fragment, it not.
my fragment
public class MessageFragment extends Fragment {
private FragmentMessageBinding binding;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
binding = FragmentMessageBinding.inflate(inflater,container,false);
NavController navController = NavHostFragment.findNavController(MessageFragment.this);
NavigationUI.setupWithNavController(binding.answerNavView22, navController);
return binding.getRoot();
}
in xml of fragment
<RelativeLayout
android:backgroundTint="#E3E1E1"
android:layout_marginTop="2dp"
android:layout_marginHorizontal="2dp"
android:visibility="visible"
android:id="@+id/layout_answer"
android:layout_width="0dp"
android:layout_height="0dp"
android:animateLayoutChanges="true"
android:background="@drawable/corner_top"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar2">
<androidx.fragment.app.FragmentContainerView
android:layout_below="@id/answer_nav_view22"
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_answer" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:background="#E3E1E1"
android:id="@+id/answer_nav_view22"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="@menu/menu_answer_nav" />
</RelativeLayout>
i checked id menu , it same with id in nav_answer. i dont know why, please help me!
have a nice day, everyone!
Upvotes: 0
Views: 49
Reputation: 474
Mình thấy như bạn đang làm thì nó sẽ là fragment trong fragment (host sẽ là fragment cha và mỗi tab trong bottom nav sẽ là frag con). Navigation component đâu có support dạng này
Upvotes: 1