【发布时间】:2022-08-17 21:46:27
【问题描述】:
我的navigation.xml 有以下代码
<?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\"
xmlns:tools=\"http://schemas.android.com/tools\"
android:id=\"@+id/mobile_navigation\"
app:startDestination=\"@+id/navigation_home\">
<fragment
android:id=\"@+id/navigation_notifications\"
android:name=\"com.elyeproj.bottombarfragmentsswitching.ContainerFragment\"
android:label=\"@string/title_notifications\"
tools:layout=\"@layout/fragment_container\" >
<argument
android:name=\"FragmentKey\"
app:argType=\"string\"
android:defaultValue=\"@string/title_notifications\" />
<argument
android:name=\"FragmentColor\"
app:argType=\"string\"
android:defaultValue=\"#00FFFF\" />
</fragment>
</navigation>
其中@string/title_notifications 将返回Notifications
但是,它在android:defaultValue=\"@string/title_notifications\" 处出错
<argument
android:name=\"FragmentKey\"
app:argType=\"string\"
android:defaultValue=\"@string/title_notifications\" />
错误是
Caused by: org.xmlpull.v1.XmlPullParserException: unsupported value \'Notifications\' for string. You must use a \"reference\" type to reference other resources.
@string/title_notifications 肯定有 Notifications 的值,因为它在 fragment 标记中使用得很好。
如果我转换为
<argument
android:name=\"FragmentKey\"
app:argType=\"string\"
android:defaultValue=\"Notifications\" />
然后它编译得很好。
为什么argument标签不能使用String资源?
标签: android android-architecture-navigation android-navigation-graph