12

我使用 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.
4

1 回答 1

26

要使用全局操作,您需要为导航图提供一个 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">
于 2018-06-12T08:43:21.197 回答