<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="0dp"
android:layout_height="52.0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_navigation"> </android.support.design.widget.BottomNavigationView>
</android.support.constraint.ConstraintLayout>

在res-->menu添加 xml(如果没有menu就新创建一个)这里我新建一个名为bottom_navigation.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <item
android:id="@+id/item_1"
android:icon="@mipmap/ic_launcher"
android:title="首页"/> <item
android:id="@+id/item_2"
android:icon="@mipmap/ic_launcher"
android:title="消息" /> <item
android:id="@+id/item_3"
android:icon="@mipmap/ic_launcher"
android:title="动态" />
<item
android:id="@+id/item_4"
android:icon="@mipmap/ic_launcher"
android:title="我" />
</menu>

测试发现放3-4个最为合适,个人感觉3个最美观

res/color/bottom_nav_seletor.xml 修改文字选择颜色

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorPrimary" android:state_checked="true" />
<item android:color="@color/colorPrimary" android:state_pressed="true" />
<item android:color="@color/colorPrimary" android:state_selected="true" />
<item android:color="@color/black" />
</selector>

在bottom_navigation.xml 增加属性

app:itemIconTint="@color/bottom_nav_seletor" 设置选择器  这个时候导航导航设置为3个能看出来效果
修改图标类似res/drawable 新建选择器
 android:icon="@mipmap/ic_launcher" 这地方设置选择器的XML文件名就可以了

BottomNavigationView 使用的更多相关文章

  1. 关于Android中使用BottomNavigationView切换横屏导致返回主页的问题

    问题: 如图,"发现"页即为主页,然后我们切换到"我"页,一切正常. 那么问题来了,如果切换到"我"页后把手机横屏,则会出现下面的情况. 嗯 ...

  2. 第三十七篇-BottomNavigationVIew底部导航的使用

    效果图: 添加底部导航和viewpaper 设置底部导航在底部 app:layout_constraintBottom_toBottomOf="parent" 新建四个fragme ...

  3. Android 底部按钮BottomNavigationView + Fragment 的使用(二)

    这里来试验BottomNavigationView + Fragment 底部按钮通过点击底部选项,实现中间的Fragment进行页面的切换. 使用BottomNavigationView 控件,实现 ...

  4. Android 底部按钮BottomNavigationView + Fragment + viewPager 的使用(一)

    实现的效果,左右滑动,底部栏跟着滑动,中间加的是分帧的页面        上代码:主页面activity_main.xml <?xml version="1.0" encod ...

  5. BottomNavigationView结合ViewPager

    BottomNavigationView是Google推出的底部导航栏组件,在没有这些底部导航组件之前,Android开发者多使用的是RadioGroup,在上一个项目开发中我们使用了Google的B ...

  6. BottomNavigationView的使用

    BottomNavigationView的使用 废话少说, 先看东西 依赖 implementation 'com.android.support:design:26.1.0' 布局 //用这个控件需 ...

  7. 014 Android BottomNavigationView 底部导航组件使用

    1.导入BottomNavigationView组件(点击下载按钮,安装组件) 2.新建菜单 (1)app--->src-->main--->res ,选中res目录右击new--- ...

  8. android BottomNavigationView 底部显示3个以上的item

    你现在可以用app:labelVisibilityMode="[labeled, unlabeled, selected, auto] labeled 所有的标签都是可见的. unlabel ...

  9. BottomNavigationView 的使用

    转载请注明出处:http://blog.csdn.net/wl9739/article/details/52875710 BottomNavigationView 很早之前就在 Material De ...

随机推荐

  1. flask请求上下文

    先看一个例子: #!/usr/bin/env python # -*- coding:utf-8 -*- import threading # local_values = threading.loc ...

  2. 匿名函数lambda及面试题三道

    # 函数名 = lambda 参数 :返回值. 匿名函数只是函数,如果要通过可迭代对象给匿名函数传参,就需要使用 map 或者 filter calc = lambda n:n**n calc(1)c ...

  3. JavaScript下实现交换数组元素上下移动例子

    // 交换数组元素    var swapItems = function(arr, index1, index2) {        arr[index1] = arr.splice(index2, ...

  4. unity中将多个图片进行椭圆排序

    //保存需要排序的精灵容器 public GameObject[] Sprites; public Transform centrePoint;//椭圆的中心点 ;//每个方块间的角度偏移 //保存位 ...

  5. pass,break,continue的使用场景

    # ### 关键字的使用 pass / break / continue # pass 过 起到占位的作用 if 5 == 5: pass print(123) # break 只能应用在循环当中 用 ...

  6. format 插入一个字符,%d,%n

  7. VS Code 工具配置和格式化

    { "onSave": true, "javascript": { "indent_size": 2, "indent_char& ...

  8. 触发移动App崩溃的测试场景

    验证在有不同的屏幕分辨率,操作系统和运营商的多个设备上的App行为. 用新发布的操作系统版本验证App的行为. 验证在如隧道,电梯等网络质量突然改变的环境中的App行为. 通过手动网络从蜂窝更改到Wi ...

  9. shell脚本监测DNS链接状态给传给zabbix值

    #!/bin/sh time_out=0 querygt3s=0 i=1 while [[ $i -le 15 ]] do i=`expr $i + 1` sleep 2 while read lin ...

  10. 【Linux常用命令】

    1. ps aux | grep nginx 使用场景:是想查看nginx的打印日志,又不知道nginx的日志路径. ps :是查看进程的命令.使用该命令 可以确定有哪些进程正在运行和运行的状态.进程 ...