Android architecture component navigation: toolbar back button missing, back not working

前端 未结 1 1912
清歌不尽
清歌不尽 2021-01-24 07:36

I\'m trying the jetpack navigation and can\'t show the navigation back button when I move to a new fragment.

NavigationActivity.kt

class NavActivity : Ap         


        
1条回答
  •  花落未央
    2021-01-24 08:05

    Edit: Your DetailFragment contains the line

    DataBindingUtil.setContentView(requireActivity(),
        R.layout.fragment_detail)
    

    which is resetting the content of your Activity to only be your fragment_detail layout, wiping out the NavHostFragment and everything else.

    You should be using DataBindingUtil.bind(view)!! instead.

    Original answer (you should still do this, but the above answer is actually what solves the problem)

    Your ConstraintLayout is missing quite a few constraints (your views should be a vertical chain, where every app:layout_constraintTop_toBottomOf has an alternative app:layout_constraintBottom_toTopOf on the other element, etc.).

    Since you have a single set of three vertically aligned items, you don't need a ConstraintLayout - just a LinearLayout is enough:

     
    
    
        
    
        
    
        
    
    

    0 讨论(0)
提交回复
热议问题