美文网首页
【白水日记】Navigtion(二)

【白水日记】Navigtion(二)

作者: d2665f7588cb | 来源:发表于2021-02-26 10:09 被阅读0次

新建一个navigation配置文件,创建3个fragment

<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"

    android:id="@+id/graph_bottom_navigation_bar_activity"

    app:startDestination="@id/left">

    <fragment

        android:id="@+id/left"

        android:name="com.chip.testnav.left"

        android:label="fragment_left"

        tools:layout="@layout/fragment_left" />

    <fragment

        android:id="@+id/mid"

        android:name="com.chip.testnav.mid"

        android:label="fragment_mid"

        tools:layout="@layout/fragment_mid" />

    <fragment

        android:id="@+id/right"

        android:name="com.chip.testnav.right"

        android:label="fragment_right"

        tools:layout="@layout/fragment_right" />

</navigation>

简单写一个上fragment,下btn的界面,配置类似,至少需要写好name和navGraph

bottomNavigationView配置如下

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item

        android:id="@+id/mid"

        android:icon="@drawable/ic_launcher_foreground"

        android:title="中"/>

    <item

        android:id="@+id/right"

        android:icon="@drawable/ic_launcher_foreground"

        android:title="右"/>

    <item

        android:id="@+id/left"

        android:icon="@drawable/ic_launcher_foreground"

        android:title="左"/>

</menu>

    将navController和View绑定,这里推荐将<fragment>和<item>标签下的id写成一样的,这样会节省代码,否则需要自己实现setOnNavigationItemSelectedListener,找到对应id通过navController执行跳转fragment的逻辑,除非有打点统计的需求,否则建议写成id相同的情况

可以看到NavigationUI类中的方法

    大部分都是将NavController和UI绑定,支持BottomNavigationVIew,ToolBar,DrawerLayout,CollapsingToolbarLayout,详情可参看

https://developer.android.google.cn/guide/navigation/navigation-ui

NavigationUI的setupWithNavController绑定的主要内容就是帮开发者实现setOnNavigationItemSelectedListener的点击行为,如果使用其他控件,需要自己实现

---------------------------------------------------------------------------

    DeepLink是Navigation封装的scheme功能,在design界面可以手动添加一个scheme,

生成代码

在deeplink标签下,可以看到约定的uri协议

能用到的一般有两个地方,推送跳转和端外跳转:

推送主要实现pendintent方法,设置好对应的graph,id即可

使用端外协议跳转,需要配置一个参数

即可实现对应跳转逻辑

相关文章

  • 【白水日记】Navigtion(二)

    新建一个navigation配置文件,创建3个fragment

  • 【白水日记】Navigtion

    Navigation是jetpack中的一个ui控件,使用该组件可方便管理fragment的导航行为,甚至可以图...

  • 【白水日记】Gradle(二)

    gradle稍微复杂一点的能力,就是gradle插件,可以提供具体的构建功能task,提高代码的复用性,编译jav...

  • 【白水日记】关于音频(二)

    音频在传输和使用的过程中,需要进行压缩,压缩的方向一般是压缩的比例和压缩的速度。 常用的思路就是消除冗余信息,因为...

  • 【白水日记】Coroutines

    在kotlin中,协程是方便而优雅处理长时间运行任务的方案 kotlin协程使得原来基于回调的代码改为了顺序编写,...

  • 【白水日记】IntentService

    IntentService继承自Service,适合处理短任务,核心实现是 ServiceHandler和Loop...

  • 【白水日记】WorkManager

    WorkManager适合不实时完成任务的场景,同时满足了电量和体验的。由于内部有自己的数据库维护着任务,Wo...

  • 【白水日记】Gradle

    关于gradle,是我们熟悉又陌生的事物,每次运行项目都在用,但是一些细节,却不太了解,不如做一次查缺补漏 gr...

  • 【白水日记】JobIntentService

    JobIntentService本质也是一个Service,一看job开头的系统组件,基本就是JobSchedul...

  • 白水二章

    白水二章 王赵民 小华山 白水历史悠久,仓颉造字,杜康酿酒,雷公造瓷,蔡伦造纸,彰显中华民族的灿烂文明,令无数白水...

网友评论

      本文标题:【白水日记】Navigtion(二)

      本文链接:https://www.haomeiwen.com/subject/ccxwxltx.html