Navigation Architecture Component - Dialog Fragments

后端 未结 10 565
[愿得一人]
[愿得一人] 2020-12-24 02:01

Is it possible to use the new Navigation Architecture Component with DialogFragment? Do I have to create a custom Navigator?

I would love to use them with the new fe

相关标签:
10条回答
  • 2020-12-24 02:36

    No, as of the 1.0.0-alpha01 build, there is no support for dialogs as part of your Navigation Graph. You should just continue to use show() to show a DialogFragment.

    0 讨论(0)
  • 2020-12-24 02:40

    Updated for:

    implementation "androidx.navigation:navigation-ui-ktx:2.2.0-rc04"
    

    And use in my_nav_graph.xml

    <dialog
    android:id="@+id/my_dialog"
    android:name="com.example.ui.MyDialogFragment"
    tools:layout="@layout/my_dialog" />
    
    0 讨论(0)
  • 2020-12-24 02:42

    Yes it is possible, You can access view of parent fragment from dialog fragment by calling getParentFragment().getView() . And use the view for navigation.

    Here is the example

    Navigation.findNavController(getParentFragment().getView()).navigate(R.id.nextfragment);
    
    0 讨论(0)
  • 2020-12-24 02:42

    Yes, It is possible now. In it's initial release it wasn't possible but now from "androidx.navigation:navigation-fragment:2.1.0-alpha03" this navigation version you can use dialog fragment in navigation component.

    Check this out:- Naviagtion dialog fragment support

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