SafeArgs不会生成

问题描述 投票:0回答:1

我正在使用导航组件,但无法生成Args类,因此可以通过以下方式在目的地Fragment中使用它:

private val myArgs by navArgs<MyDestFragmentArgs>()

// later in code access properties from args
username = myArgs.username

我看到生成了MySourceFragmentDirections,所以我假设插件已正确使用。我尝试在Android Studio中清理和重建项目,但没有看到生成任何* Args类。

我的nav_graph.xml包含:

<fragment
    android:id="@+id/mySourceFragment"
    android:name="com.example.MySourceFragment"
    android:label="@string/nav_title_source"
    tools:layout="@layout/source_fragment">

    <action
        android:id="@+id/action_to_dest"
        app:destination="@id/myDestFragment">

        <argument
            android:name="username"
            app:argType="string" />

    </action>

</fragment>
uinavigationcontroller android-safe-args
1个回答
0
投票
<fragment android:id="@+id/mySourceFragment" android:name="com.example.MySourceFragment" android:label="@string/my_source_screen_title" tools:layout="@layout/my_source_fragment"> <action android:id="@+id/action_to_dest" app:destination="@+id/myDestinationFragment" /> </fragment> <fragment android:id="@+id/myDestinationFragment" android:name="com.example.MyDestinationFragment" android:label="@string/my_dest_screen_title" tools:layout="@layout/my_dest_fragment"> <argument android:name="username" app:argType="string" /> </fragment>
© www.soinside.com 2019 - 2024. All rights reserved.