android - 带有参数或操作的目标必须具有“名称”或“标识”属性
问题描述
我使用 Android 导航组件创建了一个全局操作,编译代码时出现以下错误
<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"
app:startDestination="@id/homeEnumerationFragment">
<fragment
android:id="@+id/homeEnumerationFragment"
android:name="org.southasia.ghru.ui.homeenumeration.HomeEnumerationFragment"
android:label="HomeEnumerationFragment"
tools:layout="@layout/home_enumeration_fragment"></fragment>
<fragment
android:id="@+id/stationFragments"
android:name="org.southasia.ghru.ui.station.StationFragment"
android:label="StationFragment"
tools:layout="@layout/station_fragment"/>
<fragment
android:id="@+id/devicesFragment"
android:name="org.southasia.ghru.ui.devices.DevicesFragment"
android:label="DevicesFragment"
tools:layout="@layout/devices_fragment"/>
<action android:id="@+id/action_global_stationFragments3" app:destination="@+id/stationFragments"/>
错误:
Error: Destination with arguments or actions must have 'name' or 'id' attributes.
解决方案
要使用全局操作,您需要为导航图提供一个 id(目前它不是自动生成的)。只需将 'id' 属性添加到您的导航元素,如下所示:
<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"
app:startDestination="@id/homeEnumerationFragment"
android:id="@+id/main">
推荐阅读
- list - ansible:引用同一列表中的变量
- pandas - 熊猫多个特定条件中的分组计数
- python - 为什么函数不接受新的赋值?
- scala - scala 中 Try 的返回类型
- reactjs - React.js:如何在保存后强制反应表再次呈现?(钩子)
- javascript - 如何使用不同的颜色来标记 cytoscape.js 中的节点?
- regex - PowerShell - 将文本提取到变量中(RegEx?)
- augmented-reality - 使用 AR.js 进行图像跟踪 - 自定义图像描述符的问题
- json - 使用 struct 创建带有 key:value 作为标签名称的 JSON 输出的问题
- r - 如何更改决策树图