Navigate to fragment on FAB click (Navigation Architecture Components)

前端 未结 4 950
囚心锁ツ
囚心锁ツ 2021-01-04 10:40

I have no idea how to, using the new navigation architecture component, navigate from my main screen (with a FloatingActionButton attatched to a BottomApp

4条回答
  •  猫巷女王i
    2021-01-04 11:05

    You could have your BottomAppBar in MainActivity and access your FloatingActionButton in your fragment as follows

    activity?.fab?.setOnClickListener { 
        /*...*/
        findNavController().navigate(R.id.action_firstFragment_to_secondFragment, mDataBundle)
    }
    

    You could hide the BottomAppBar from another activity as follows

    (activity as AppCompatActivity).supportActionBar?.hide()
    

    Make sure you .show() the BottomAppBar while returning to previous fragment

提交回复
热议问题