Android底部导航栏实现之BottomNavigationBar

来源:互联网 发布:java清除cookie 编辑:程序博客网 时间:2024/05/17 21:47

上篇文件讲解了官方的BottomNavigationView


这篇讲解下第三方的BottomNavigationBar

引入依赖

    compile 'com.ashokvarma.android:bottom-navigation-bar:1.3.1'

查看布局

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:orientation="vertical">    <LinearLayout        android:id="@+id/tb"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:orientation="vertical" />    <com.ashokvarma.bottomnavigation.BottomNavigationBar        android:id="@+id/bottom_navigation_bar"        android:layout_gravity="bottom"        android:layout_alignParentBottom="true"        android:layout_width="match_parent"        android:layout_height="wrap_content">    </com.ashokvarma.bottomnavigation.BottomNavigationBar></RelativeLayout>

实现:

 /**         * 设置个性化---动画         * Mode和BackgroundStyle分别有三种,分别包含一种Default模式 总共三种模式。         * FIXED+STATIC         * FIXED+RIPPLE         * SHIFTING+RIPPLE         */        bottomNavigationBar.setMode(BottomNavigationBar.MODE_FIXED);        bottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_RIPPLE);        bottomNavigationBar.addItem(new BottomNavigationItem(R.mipmap.foot_ask_image,"第一个").setActiveColorResource(R.color.colorAccent))                .addItem(new BottomNavigationItem(R.mipmap.foot_look_live,"第二个").setActiveColorResource(R.color.colorPrimaryDark))                .setActiveColor(R.color.button_text)                .addItem(new BottomNavigationItem(R.mipmap.foot_seek_cricle,"第三个").setActiveColorResource(R.color.colorAccent))                .setActiveColor(R.color.button_text)                .initialise();

setActiveColorResources设置选中的颜色

mBottomNavigationBar.setBarBackgroundColor(R.color.blue);设置底部导航栏颜色


添加角标

BadgeItem badgeItem = new BadgeItem();        badgeItem.setHideOnSelect(false)                .setText("10")                .setBackgroundColorResource(R.color.orange)                .setBorderWidth(0);//导航栏中的tab添加小圆点mBottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.icon_one, R.string.tab_one).setActiveColorResource(R.color.green).setBadgeItem(badgeItem));

运行效果截图:

1
这里写图片描述

详情看Demo中BottomActivity类

阅读全文
0 0
原创粉丝点击