'Navigation component fragment label is not working for with attribute string
The fragment is in a module, So I made an attribute. The fragment is just showing that string attribute
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
app:layout_constraintTop_toTopOf="parent"
android:text="?attr/app_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.constraintlayout.widget.ConstraintLayout>
My Fragment,
class TestFragment: Fragment(R.layout.fragment_test)
The attribute is in the module
<attr name="app_name" format="string|reference"/>
?attr/app_name
perfectly shows the value. However, when I use the same attribute in the navigation label, it shows some sort of number. My navigation graph is ,
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_graph"
app:startDestination="@id/testFragment">
<fragment
android:id="@+id/testFragment"
android:name="com.example.TestFragment"
android:label="?attr/app_name" />
</navigation>
Does it work in navigation component? Thanks in advance.
Solution 1:[1]
Create string.xml in your module, then use android:label="@string/app_name"
Solution 2:[2]
Hope not too late but I think correct format is <attr name="title" format="string"/>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Madi |
Solution 2 | AndroidByLazy |