作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在学习 Android NavigationUI,并尝试使用 Safe Args 中的字符串默认值设置工具栏标题。但是有一些问题。
“字符串资源”文件:
<string name="title_add_item">Add new items</string>
Title: {title}
争论。
<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/nav_graph"
app:startDestination="@id/mainFragment">
<fragment
android:id="@+id/addNewItemFragment"
android:name="com.myapplication.AddNewItemFragment"
android:label="Title: {title}"
tools:layout="@layout/fragment_add_new_item" >
<argument
android:name="title"
app:argType="string"
android:defaultValue="@string/title_add_item" />
</fragment>
<fragment
android:id="@+id/mainFragment"
android:name="com.myapplication.MainFragment"
android:label="fragment_main"
tools:layout="@layout/fragment_main" >
<action
android:id="@+id/action_to_add_items_fragment"
app:destination="@id/addNewItemFragment" />
</fragment>
{app:argType="string"}
我收到一个错误:
Caused by: org.xmlpull.v1.XmlPullParserException: unsupported value 'Add new items' for string. You must use a "reference" type to reference other resources.
{app:argType="reference"}
应用程序有效,但我的标题中有一个数字(我认为这是一个资源 ID):
最佳答案
References to resources are supported only in reference types. Using aresource reference in any other type results in an exception.
app:argType="string"
对字符串值进行硬编码。或尝试以编程方式设置,直到它得到解决。
关于android - 如何从 SafeArgs 中的资源中获取默认字符串值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57274992/
我是一名优秀的程序员,十分优秀!