/BottomNavigationViewEx

An android lib for enhancing BottomNavigationView. 一个增强BottomNavigationView的安卓库。

Primary LanguageJavaMIT LicenseMIT

BottomNavigationViewEx

An android lib for enhancing BottomNavigationView.

MIT License api 15+

About Us

天宇工作室

Feature

  • getCurrentItem

    Get current checked item

  • setCurrentItem

    Set current checked item

  • enableShiftingMode

    Open or close shifting mode for navigation bar

  • enableItemShiftingMode

    Open or close shifting mode for menu item

  • enableAnimation

    Open or close animation for menu item

  • setTextVisibility

    Set the visibility of text

  • setIconVisibility

    Set the visibility of icon

Example

With ViewPager

Adding to project

Dependency

compileSdkVersion >= 25 and add design :

compile 'com.android.support:design:25.0.0'

Importing to project

Example for Gradle:

Step 1. Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

Step 2. Add the dependency

compile 'com.github.ittianyu:BottomNavigationViewEx:1.1.0'

and for Maven:

Step 1. Add it in your root build.gradle at the end of repositories:

<repositories>
	<repository>
	    <id>jitpack.io</id>
	    <url>https://jitpack.io</url>
	</repository>
</repositories>

Step 2. Add the dependency

<dependency>
    <groupId>com.github.ittianyu</groupId>
    <artifactId>BottomNavigationViewEx</artifactId>
    <version>1.1.0</version>
</dependency>

Manual:

Downloading BottomNavigationViewEx.java and copying it to you project。

Getting started

Adding a custom widget in xml :

<com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
    android:id="@+id/bnve"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    app:itemBackground="@color/colorPrimary"
    app:itemIconTint="@color/item_text_color"
    app:itemTextColor="@color/item_text_color"
    app:menu="@menu/menu_navigation_with_view_pager" />

Binding view in Activity and setting style:

BottomNavigationViewEx bnve = (BottomNavigationViewEx) findViewById(R.id.bnve);

bnve.enableAnimation(false);

bnve.enableShiftingMode(false);

bnve.enableItemShiftingMode(false);

bnve.setTextVisibility(false);

bnve.setIconVisibility(false);

bnve.setCurrentItem(1);

bnve.getCurrentItem();

Other usage is the same as official BottomNavigationView. You can click here for detail.

References

The lib is based on BottomNavigationView in Support Library 25 design.

I found it was inflexible when I try in demo. For example, I can't change the current checked item by code. So I write a class extends it to provide some useful method.

You no need to worry about stability. Because I minimise modifying by reflecting.

License

MIT License

Copyright (c) 2016 ittianyu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


----------

BottomNavigationViewEx

一个增强BottomNavigationView的安卓库。

MIT License api 15+

关于我们

天宇工作室

功能

  • getCurrentItem

    获取当前选中的项

  • setCurrentItem

    设置当前选中的项

  • enableShiftingMode

    开启或关闭导航条的位移模式

  • enableItemShiftingMode

    开启或关闭子菜单的位移模式

  • enableAnimation

    开启或关闭子菜单的文字和图片动画

  • setTextVisibility

    设置子菜单文本可见性

  • setIconVisibility

    设置子菜单图片可见性

例子

With ViewPager

加入工程

依赖

compileSdkVersion >= 25 且添加 design 依赖包:

compile 'com.android.support:design:25.0.0'

导入本库

Gradle例子:

步骤 1. 在工程根目录的 build.gradle 最后添加如下代码:

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

步骤 2. 添加依赖

compile 'com.github.ittianyu:BottomNavigationViewEx:1.1.0'

Maven例子:

步骤 1. 在工程根目录的 build.gradle 最后添加如下代码:

<repositories>
	<repository>
	    <id>jitpack.io</id>
	    <url>https://jitpack.io</url>
	</repository>
</repositories>

步骤 2. 添加依赖

<dependency>
    <groupId>com.github.ittianyu</groupId>
    <artifactId>BottomNavigationViewEx</artifactId>
    <version>1.1.0</version>
</dependency>

手动导入:

下载文件 BottomNavigationViewEx.java 并复制到你的工程中。

开始使用

xml 布局中添加自定义控件:

<com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
    android:id="@+id/bnve"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    app:itemBackground="@color/colorPrimary"
    app:itemIconTint="@color/item_text_color"
    app:itemTextColor="@color/item_text_color"
    app:menu="@menu/menu_navigation_with_view_pager" />

Activity 中绑定控件,并设置样式:

BottomNavigationViewEx bnve = (BottomNavigationViewEx) findViewById(R.id.bnve);

bnve.enableAnimation(false);

bnve.enableShiftingMode(false);

bnve.enableItemShiftingMode(false);

bnve.setTextVisibility(false);

bnve.setIconVisibility(false);

bnve.setCurrentItem(1);

bnve.getCurrentItem();

其他用法和官方 BottomNavigationView 一样。 详情点击这里

来源

本库修改自安卓官方 Support Library 25 design 中的 BottomNavigationView

我在尝试使用官方的库时,发现缺少灵活性。比如官方并没有提供切换当前选中项的方法。所以我在此基础上包装了一层,对外公开了一些方法。

你完全没有必要担心库的稳定性,因为我是使用反射对父类进行最小限度的修改。

授权

MIT License

Copyright (c) 2016 ittianyu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.