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

前端 未结 13 1997
误落风尘
误落风尘 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:27

    You have to set host navigation like below xml:

    
    
        
    
        
    
        
    
    

    Setup With Navigation Controller :

    NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_host_fragment);
    NavigationUI.setupWithNavController(bottomNavigationView, navHostFragment.getNavController());
    

    menu_bottom_navigation.xml :

    
    
        
        
    
        
    
    

    nav_graph.xml :

    
        
    
        
    
        
    
    

    By setting up the same id of "nav_graph" to "menu_bottom_navigation" will handle the click of bottom navigation.

    You can handle back action using popUpTo property in action tag.

提交回复
热议问题