Android Jetpack Navigation, BottomNavigationView with Youtube or Instagram like proper back navigation (fragment back stack)?

前端 未结 13 2004
误落风尘
误落风尘 2020-12-12 10:25

Android Jetpack Navigation, BottomNavigationView with auto fragment back stack on back button click?

What I wanted, after choosing multiple tabs one after another by

13条回答
  •  轮回少年
    2020-12-12 11:05

    In the jetpack navigation, you have to make changes in only single navigation graph xml file for handle navigation, handle backstacks, custom animations, pass arguments between fragments.

    If you want simply back to previous fragment,

    
    
    
        btn_cancel.setOnClickListener {
                    it.findNavController().popBackStack()
                }
    

    If you want to clear all backstacks and go to new fragment

    
    
    
     btn_submit.setOnClickListener {
                       it.findNavController().navigate(DeleteEmployeeFragmentDirections.actionDeleteEmployeeFragmentToEmployeesListFragment2())
            }
    

    For more reference: Jetpack Navigation Example

提交回复
热议问题