android导航使用教程,android BottomNavigationView的简单使用教程

每个android app都有BottomNavigationView导航,本人开发中刚刚使用到了BottomNavigationView,于是按照android developer官网特意做了一个符合material design设计得bottom navigation的简单使用教程,很容易学会的哦。

注:为便于理解,先让各位看看本人项目的目录结构,如图。

41cfb17c572f761fc16fc6f21e16cc02.png

第一步:在build.gradle的dependencies标签中导入android material design设计所需要的gradle依赖包,因为我们是严格按照这种标准设计出的导航,代码如下。compile 'com.android.support:design:25.0.0'

第二步:新建一个layout的xml文件,该文件最好放在自己新建的menu文件夹下,放在layout文件夹下回报错,本人新建了一个activity_my_navigation_items.xml的文件夹,文件名自己随便命名即可,该文件就是用来定义底部菜单导航的,也就是BottomNavigationView,代码如下。<?xml  version="1.0" encoding="utf-8"?>

android:title="消息"

android:icon="@mipmap/ic_launcher" />

android:title="联系人"

android:icon="@mipmap/ic_launcher" />

android:title="我的"

android:icon="@mipmap/ic_launcher" />

第三步:在activity_main.xml中引入我们定义好的BottomNavigationView(底部导航),因为activity_main.xml是我们android app的入口,代码如下。<?xml  version="1.0" encoding="utf-8"?>

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/activity_main"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context="com.baidu.notificationdemo.MainActivity">

xmlns:android=""

xmlns:app=""

android:id="@+id/bottom_navigation"

android:layout_alignParentBottom="true"

android:layout_width="match_parent"

android:layout_height="56dp"

app:itemBackground="@color/colorPrimaryDark"

app:itemIconTint="@color/white"

app:itemTextColor="@color/white"

android:layout_gravity="start"

app:menu="@menu/activity_my_navigation_items" />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值