为什么在Android Studio 中导航文件有两个userMessage?
Why does the navigation file have two userMessage in Android Studio?
以下代码来自项目architecture-samples。可以看到here.
为什么导航文件在Android Studio 中有两个userMessage
?
顺便说一句,在我删除最后一个 <argument android:name="userMessage" android:defaultValue="0" />
后,应用程序可以 运行
还有,在我看来元素<navigation>
只包含子元素<fragment>
,为什么下面的元素<navigation>
可以包含子元素<argument>
?
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_graph"
app:startDestination="@id/tasks_fragment_dest">
...
<fragment
android:id="@+id/tasks_fragment_dest"
android:name="com.example.android.architecture.blueprints.todoapp.tasks.TasksFragment"
android:label="@string/app_name">
<action
android:id="@+id/action_tasksFragment_to_statisticsFragment"
app:destination="@id/statistics_fragment_dest" />
<action
android:id="@+id/action_tasksFragment_to_taskDetailFragment"
app:destination="@id/task_detail_fragment_dest" />
<action
android:id="@+id/action_tasksFragment_to_addEditTaskFragment"
app:destination="@id/add_edit_task_fragment_dest" />
<argument
android:name="userMessage"
app:argType="integer"
android:defaultValue="0" />
</fragment>
<argument
android:name="userMessage"
android:defaultValue="0" />
</navigation>
我认为这是一个错字。第二个
<argument
android:name="userMessage"
android:defaultValue="0" />
应该删除。没有它,代码很好。导航的解析将忽略第二个 userMessage。
可能开发人员没有发现它,因为结果没有错误或功能丢失。
以下代码来自项目architecture-samples。可以看到here.
为什么导航文件在Android Studio 中有两个userMessage
?
顺便说一句,在我删除最后一个 <argument android:name="userMessage" android:defaultValue="0" />
还有,在我看来元素<navigation>
只包含子元素<fragment>
,为什么下面的元素<navigation>
可以包含子元素<argument>
?
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_graph"
app:startDestination="@id/tasks_fragment_dest">
...
<fragment
android:id="@+id/tasks_fragment_dest"
android:name="com.example.android.architecture.blueprints.todoapp.tasks.TasksFragment"
android:label="@string/app_name">
<action
android:id="@+id/action_tasksFragment_to_statisticsFragment"
app:destination="@id/statistics_fragment_dest" />
<action
android:id="@+id/action_tasksFragment_to_taskDetailFragment"
app:destination="@id/task_detail_fragment_dest" />
<action
android:id="@+id/action_tasksFragment_to_addEditTaskFragment"
app:destination="@id/add_edit_task_fragment_dest" />
<argument
android:name="userMessage"
app:argType="integer"
android:defaultValue="0" />
</fragment>
<argument
android:name="userMessage"
android:defaultValue="0" />
</navigation>
我认为这是一个错字。第二个
<argument
android:name="userMessage"
android:defaultValue="0" />
应该删除。没有它,代码很好。导航的解析将忽略第二个 userMessage。
可能开发人员没有发现它,因为结果没有错误或功能丢失。