<?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. 用图片作为label,for属性IE下不起作用

    IE浏览器存在一个BUG,当你使用label的for属性达到点击label使对应的表单元素聚焦,label中的内容为图片时,IE浏览器下不起作用. 例如: <input type="c ...

  2. Python *Mix_w5

    1. 字典dict dict  用{}来表示 ,键值对数据{key:value}  key具有唯一性 键:都必须是可哈希的,除了列表,不可变的数据类型都可以当做字典中的键 值  没有任何限制 2. 字 ...

  3. 从零开始学Shell(二)

    $1,$2....${10},${11},[root@localhost cee]# cat p.sh #!/bin/bash#file_name:p.shecho $1 $2[root@localh ...

  4. 操作系统の实验四 windows中线程的创建和同步控制

    摘要: 1.创建信号量 HANDLE CreateSemaphore( LPSECURITY_ATTIBUTES  lpSemaphoreAttributes, LONG lInitialCount; ...

  5. ES6和ES5变量声明的区别(var let const)

    // es5的语法与es6的语法区别 // var let const console.log(name);//undefine,不会报错,因为变量声明会提到作用域的最前面 var name=&quo ...

  6. 5.使用std的迭代器访问并修改图像

    void Test_ColorReduceByIterator() { Mat g_srcImage=imread("D:\\OpenCV Projects\\OpenCV_Test_Ima ...

  7. JS中的一等公民:函数

    在JavaScript中,函数可以 作为值赋给一个变量 作为参数传递给另一个函数 作为另一个函数的返回值 所以我们说JavaScript的函数是“一等公民”. 赋值: var foo = functi ...

  8. java特殊抽象类-接口

  9. 蘑菇街支付架构 PDF 下载

    蘑菇街支付架构 PDF 下载 下载地址:链接:https://pan.baidu.com/s/1ZffetaUhVMOzb9j2PSQJIQ 密码:iays http://www.java1234.c ...

  10. python爬虫出现的状态码

    1.200 --- 一切正常访问 2.301 --- 重定向新的url,永久性的 3.302 --- 重定向到临时url 4.304 --- 请求的资源未更新 5.400 --- 非法请求 6.401 ...