Giter Site home page Giter Site logo

amouly / bottomnavigationviewex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ittianyu/bottomnavigationviewex

0.0 1.0 0.0 557 KB

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

License: MIT License

Java 100.00%

bottomnavigationviewex's Introduction

BottomNavigationViewEx

An android lib for enhancing BottomNavigationView.

MIT License api 15+

About Us

天宇工作室

Features

Method Description
enableAnimation Enable or disable click item animation(text scale and icon move animation in no item shifting mode). Default true.
enableItemShiftingMode Enable the shifting mode for each item. It will has a shift animation for item if true. Otherwise the item text always be shown. Default true when item count > 3.
enableShiftingMode Enable the shifting mode for navigation. It will has a shift animation if true. Otherwise all items are the same width. Default true when item count > 3.
getBottomNavigationItemView Get private mButton in mMenuView at position
getBottomNavigationItemViews Get private mButtons in mMenuView
getCurrentItem Get the current checked item position.
getIconAt Get icon at position.
getMenuItemPosition Get menu item position in menu. Return position if success, -1 otherwise.
getOnNavigationItemSelectedListener Get OnNavigationItemSelectedListener.
setCurrentItem Set the current checked item.
setIconVisibility Change the visibility of icon.
setTextVisibility Change the visibility of text.
setupWithViewPager This method will link the given ViewPager and this BottomNavigationViewEx together so that changes in one are automatically reflected in the other. This includes scroll state changes and clicks.

Example

Style

With ViewPager

Add ViewBadger

Adding to project

Dependency

compileSdkVersion >= 25 and add design :

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

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.1'

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.1</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/selector_item_color"
    app:itemTextColor="@color/selector_item_color"
    app:menu="@menu/menu_navigation_with_view_pager" />

Binding view in Activity:

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

Disable all animations

bnve.enableAnimation(false);
bnve.enableShiftingMode(false);
bnve.enableItemShiftingMode(false);

Binding with ViewPager

// set adapter
adapter = new VpAdapter(getSupportFragmentManager(), fragments);
bind.vp.setAdapter(adapter);

// binding with ViewPager
bind.bnve.setupWithViewPager(bind.vp);

Other usage in BottomNavigationViewEx

You can see the demo.

Usage in BottomNavigationView

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+

关于我们

天宇工作室

功能

methods description
enableAnimation 开启或关闭点击动画(文字放大效果和图片移动效果)。 默认为 true.
enableItemShiftingMode 开始或关闭子菜单位移模式。 如果为 true,除了当前选中项,其他项的文本将会隐藏。 当菜单数大于3时,默认为 true。
enableShiftingMode 开始或关闭导航条位移模式。如果为 true,选中项和其他项的宽度不一样。当菜单数大于3时,默认为 true。
getBottomNavigationItemView 获取位于 position 的私有成员变量 mButton。
getBottomNavigationItemViews 获取私有成员变量 mButtons。
getCurrentItem 获取当前选中项的索引。
getIconAt 获取位于 position 的图片.
getMenuItemPosition 获取子菜单的索引。如果找不到,返回 -1。
getOnNavigationItemSelectedListener 获取 OnNavigationItemSelectedListener。
setCurrentItem 设置当前选中项。
setIconVisibility 设置图片可见性。
setTextVisibility 设置文本可见性。
setupWithViewPager 和 ViewPager 绑定,当 任何一个选中项改变时,都会自动改变另一项。

例子

样式

和 ViewPager 一起使用

带数字的小红圈

加入工程

依赖

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

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

导入本库

Gradle例子:

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

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

步骤 2. 添加依赖

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

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.1</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/selector_item_color"
    app:itemTextColor="@color/selector_item_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);

和 ViewPager 绑定####

// set adapter
adapter = new VpAdapter(getSupportFragmentManager(), fragments);
bind.vp.setAdapter(adapter);

// binding with ViewPager
bind.bnve.setupWithViewPager(bind.vp);

其他 BottomNavigationViewEx 的用法

请参考demo。

其他 BottomNavigationView 的用法

其他用法和官方 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.

bottomnavigationviewex's People

Contributors

ittianyu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.