You can create a destination from an existing fragment or activity. You can also use the Navigation Editor to create a new destination or create a placeholder to later replace with a fragment or activity.
Create a destination from an existing fragment or activity
In the Navigation Editor, if you have an existing destination type that you'd like to add to your navigation graph, click New Destination , and then click on the corresponding destination in the dropdown that appears. You can now see a preview of the destination in the Design view along with the corresponding XML in the Text view of your navigation graph.
Create a new fragment destination
To add a new destination type using the Navigation Editor, do the following:
- In the Navigation Editor, click the New Destination icon , and then click Create new destination.
- In the New Android Component dialog that appears, create your fragment. For more information on fragments, see the fragment documentation.
Back in the Navigation Editor, notice that Android Studio has added this destination to the graph.
Figure 1 shows an example of a destination and a placeholder destination.
Create a destination from a DialogFragment
If you have an existing
you can use the
<dialog> element to add the dialog to your navigation graph,
as shown in the following example:
<?xml version="1.0" encoding="utf-8"?> <navigation xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/nav_graph"> ... <dialog android:id="@+id/my_dialog_fragment" android:name="androidx.navigation.myapp.MyDialogFragment"> <argument android:name="myarg" android:defaultValue="@null" /> <action android:id="@+id/myaction" app:destination="@+id/another_destination"/> </dialog> ... </navigation>
You can use placeholders to represent unimplemented destinations. A placeholder serves as a visual representation of a destination. Within the Navigation Editor, you can use placeholders just as you would any other destination.