问题
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
- (Inside Fragment A)BottomSheetDialogFragment.show() to display the bottomSheetMenu
- NavHost(FragXYZ->FragA)
Demo:GitHub
来源:https://stackoverflow.com/questions/53417322/how-to-navigate-to-half-fragment-navigation-architecture-component