kotlin组件化底部导航fragment

nav布局
<fragment
    android:id="@+id/zhuFragment"
    android:name="com.example.mym416yk.fragment.ZhuFragment"
    android:label="fragment_zhu"
    tools:layout="@layout/fragment_zhu" >
    <action
        android:id="@+id/action_zhuFragment_to_fenFragment"
        app:destination="@id/fenFragment" />
</fragment>
<fragment
    android:id="@+id/fenFragment"
    android:name="com.example.mym416yk.fragment.FenFragment"
    android:label="fragment_fen"
    tools:layout="@layout/fragment_fen" >
    <action
        android:id="@+id/action_fenFragment_to_gouFragment"
        app:destination="@id/gouFragment" />
</fragment>
<fragment
    android:id="@+id/gouFragment"
    android:name="com.example.mym416yk.fragment.GouFragment"
    android:label="fragment_gou"
    tools:layout="@layout/fragment_gou" >
    <action
        android:id="@+id/action_gouFragment_to_woFragment2"
        app:destination="@id/woFragment2" />
</fragment>
<fragment
    android:id="@+id/woFragment2"
    android:name="com.example.mym416yk.fragment.WoFragment"
    android:label="fragment_wo"
    tools:layout="@layout/fragment_wo" />

meun——item

<item android:id="@+id/zhuFragment" android:title="首页" android:icon="@drawable/shou"></item>
<item android:id="@+id/fenFragment" android:title="视频" android:icon="@drawable/shou"></item>
<item android:id="@+id/gouFragment" android:title="社区" android:icon="@drawable/gowuche"></item>
<item android:id="@+id/woFragment2" android:title="我的" android:icon="@drawable/ic_launcher_foreground"></item>

主页

val navHostFragment = supportFragmentManager.findFragmentById(R.id.fcon) as NavHostFragment
val navController = navHostFragment.navController
val bottomNavigationView =
    findViewById<BottomNavigationView>(R.id.bnav) as BottomNavigationView
bottomNavigationView.setupWithNavController(navController)
  • 8
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值