How to navigate to Half Fragment ? (Navigation Architecture Component)

六月ゝ 毕业季﹏ 提交于 2019-12-11 17:39:58

问题


I am trying Navigation architecture Component in My app. Earlier i Used Fragment Transaction's to achieve the below feature. Basically i want to navigate from.

FragmentA->FragmentB (custom fragment partially transparent and half of screen size)

If i am using Navigation component and try

Navigation.findNavController(view).navigate(R.id.action_FragmentA_to_FragmentB)

Then the result is the FragmentA is replaced by FragmentB and the background fragment is not visible.

I want to know of a solution if it's allowed by Navigation Architecture Component.

P.S: I have heard about nested Navigation Host,But is it good to use from inside Fragment.

Update:

The FragmentB will have action's for further transaction's and example:

FragmentA->FragmentB->FragmentC (custom fragment partially transparent and half of screen size)

And Fragment C should replace FragmentB when user press back button and backStack should be maintained for all the fragment transactions.


回答1:


You can use BottomSheetDialogFragment to get the desired result.
More info: https://developer.android.com/reference/android/support/design/widget/BottomSheetDialogFragment




回答2:


TLDR:I used nested graphs for achieving the requirement.

Hello, thanks for help but navigating in BottomSheet is achieved by me using below procedure.

  • MainActivity

    • NavHost(FragXYZ->FragA)
      • (Inside Fragment A)BottomSheetDialogFragment.show() to display the bottomSheetMenu
        • (Inside Fragment B) BottomSheetDialogChildFragment(start child Fragment of BottomSheetDialogFragment using Fragment Transaction) extends NavHostFragment

Demo:GitHub



来源:https://stackoverflow.com/questions/53417322/how-to-navigate-to-half-fragment-navigation-architecture-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!