5

I based my code on this question : How to create BottomSheetDialogFragment using Navigation Architecture Component?

I want to use fragment bottom sheet with navigation component I used the following setup :

 <fragment
        android:id="@+id/mainFragment"
        android:name="package.MainFragment"
        android:label="main_fragment"
        tools:layout="@layout/main_fragment" >
        <action
            android:id="@+id/action_mainFragment_to_bottomSheet"
            app:destination="@id/bottomSheet" />
    </fragment>

    <dialog
        android:id="@+id/bottomShee"
        android:name="package.OptionFragment" />

and in the code

view.findNavController().navigate(R.id.action_mainFragment_to_bottomSheet)

But the problem is that the bottom sheet appears in another fragment and not shadowing current fragment.

is there any way to implement bottom sheet with android navigation component?

AndroLife
  • 908
  • 2
  • 11
  • 27
  • 2
    Have a look at this: https://stackoverflow.com/questions/53431473/how-to-create-bottomsheetdialogfragment-using-navigation-architecture-component – Marco RS Oct 02 '19 at 03:39
  • 1
    it's the url I referred in my question. it didn't help as I get bottom sheet being displayed in another fragment – AndroLife Oct 02 '19 at 18:01
  • I see, sorry about that. It's actually a problem I ran into as well so I just used the bottom sheet in a normal implementation and then from the parent fragment I used MyBottomSheetFragment().show(childFragmentManager, "MyTag") I don't think there is an easy way to integrate it with the navigation component without having it drawn as another fragment. But the way I explained allows you to have a parent fragment. – Marco RS Oct 03 '19 at 00:43

1 Answers1

0

Your bottom sheet fragment needs to inherit from: BottomSheetDialogFragment() and not Fragment()

StefanJo
  • 275
  • 3
  • 13