Search code examples
androidandroid-jetpackandroid-architecture-navigationandroid-jetpack-navigation

Is it possible to make the label attribute flexible in Navigation Component?


<fragment
    android:id="@+id/navigationMain_fragment_profileFragment"
    android:name="com.test.fragments.ProfileFragment"
    android:label="luq281"
    tools:layout="@layout/fragment_profile">

    <argument
        android:name="userId"
        app:argType="integer" />

    <argument
        android:name="username"
        app:argType="string" />

</fragment>

Is it possible to make the label attribute read the value from specific arguments such as the username argument?

I know how can I do it programmatically but I want to do it in XML itself.

Is it possible or not?


Solution

  • Yes it is possible.

    To use username argument as label:

    <fragment
        android:id="@+id/navigationMain_fragment_profileFragment"
        android:name="com.test.fragments.ProfileFragment"
        android:label="{username}"
        tools:layout="@layout/fragment_profile">
    
        <argument
            android:name="userId"
            app:argType="integer" />
    
        <argument
            android:name="username"
            app:argType="string" />
    
    </fragment>