Navigation Architecture Component - Dialog Fragments

后端 未结 10 667
[愿得一人]
[愿得一人] 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:17

    May 2019 Update:

    DialogFragment are now fully supported starting from Navigation 2.1.0, you can read more here and here

    Old Answer for Navigation <= 2.1.0-alpha02:

    I proceeded in this way:

    1) Update Navigation library at least to version 2.1.0-alpha01 and copy both files of this modified gist in your project.

    2) Then in your navigation host fragment, change the name parameter to your custom NavHostFragment

    
    

    3) Create your DialogFragment subclasses and add them to your nav_graph.xml with:

    
    

    4) Now launch them from fragments or activity with

    findNavController().navigate(R.id.my_dialog)
    

    or similar methods.

提交回复
热议问题