Android Navigation 组件

发布时间: 2021-02-01 11:26:39 作者: 大象笔记

Navigation 组件适用场景

The Navigation component is designed for apps that have one main activity with multiple fragment destinations. The main activity is associated with a navigation graph and contains a NavHostFragment that is responsible for swapping destinations as needed. In an app with multiple activity destinations, each activity has its own navigation graph.

Navigation 组件的构成

navigation graph 中的一些概念及名词

action 属于一个 fragment,一个 action 只能被其所属 fragment 调用。

<fragment
	android:id="@+id/blankFragment"
	android:name="com.example.cashdog.cashdog.BlankFragment"
	android:label="fragment_blank"
	tools:layout="@layout/fragment_blank" >
	<action
		android:id="@+id/action_blankFragment_to_blankFragment2"
		app:destination="@id/blankFragment2" />
</fragment>

Kotlin 获取 NavController 的三种方法

参考

我是一名山东烟台的开发者,联系作者