1- ## [ 中文版点我 或 滑动到后面 ] ( #zh ) ##
1+ ## [ 中文版点我] ( /README_ZH.md ) ##
22
33## BottomNavigationViewEx ##
44An android lib for enhancing BottomNavigationView.
@@ -31,13 +31,14 @@ An android lib for enhancing BottomNavigationView.
3131|setIconSize|Set all item ImageView size.
3232|setIconSizeAt|Set all item ImageView size which at position.
3333|setIconsMarginTop|set margin top for all icons.
34- |setIconTintList| Set the icon tint list.
34+ |setIconTintList| Set item icon tint list.
3535|setIconVisibility|Change the visibility of icon.
3636|setItemBackground| Set background of item.
3737|setItemHeight|Set menu item height.
3838|setLargeTextSize|Set all item large TextView size. Each item has tow label, one is large, another is small. Small one will be shown when item state is normal. Large one will be shown when item checked.
3939|setSmallTextSize|Set all item small TextView size. Each item has tow label, one is large, another is small. Small one will be shown when item state is normal. Large one will be shown when item checked.
4040|setTextSize|Set all item large and small TextView size.
41+ |setTextTintList|Set item TextView color.
4142|setTextVisibility|Change the visibility of text.
4243|setTypeface|set Typeface for all item TextView.
4344|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.
@@ -76,6 +77,7 @@ An android lib for enhancing BottomNavigationView.
7677![ ] ( /read_me_images/no_animation_shifting_mode_item_shifting_mode_icon.gif )
7778
7879** Attention: Something wrong on Android 4.x**
80+
7981![ ] ( /read_me_images/with_padding.jpg )
8082
8183![ ] ( /read_me_images/center_icon_only.jpg )
@@ -90,6 +92,8 @@ An android lib for enhancing BottomNavigationView.
9092
9193![ ] ( /read_me_images/icon_margin_top.jpg )
9294
95+ ![ ] ( /read_me_images/unchecked_first_time.jpg )
96+
9397
9498** With ViewPager**
9599
@@ -252,264 +256,3 @@ Thanks for [Adrián Mouly](https://github.com/amouly) | [liaolintao](https://git
252256 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
253257 SOFTWARE.
254258
255-
256-
257-
258- <br />
259- <br />
260- ----------
261-
262- <a id =" zh " > </a >
263- ## BottomNavigationViewEx ##
264- 一个增强BottomNavigationView的安卓库。
265-
266- ![ MIT License] ( https://img.shields.io/github/license/mashape/apistatus.svg ) ![ api 9+] ( https://img.shields.io/badge/API-9%2B-green.svg )
267-
268- ## 关于我们 ##
269- [ ![ 天宇工作室] ( https://github.com/ittianyu/MobileGuard/blob/master/read_me_images/logo-transparent.png?raw=true )] ( http://www.ittianyu.com )
270-
271-
272- ## 功能 ##
273-
274- |methods|description
275- | ---| ---|
276- |enableAnimation|开启或关闭点击动画(文字放大效果和图片移动效果)。 默认为 true.
277- |enableItemShiftingMode|开始或关闭子菜单位移模式。 如果为 true,除了当前选中项,其他项的文本将会隐藏。 当菜单数大于3时,默认为 true。
278- |enableShiftingMode|开始或关闭导航条位移模式。如果为 true,选中项和其他项的宽度不一样。当菜单数大于3时,默认为 true。
279- |getBottomNavigationItemView|获取位于 position 的私有成员变量 mButton。
280- |getBottomNavigationItemViews|获取私有成员变量 mButtons。
281- |getCurrentItem|获取当前选中项的索引。
282- |getIconAt|获取位于 position 的图片。
283- |getItemCount|获取子项个数。
284- |getItemHeight|获取菜单高度。
285- |getLargeLabelAt|获取位于 position 的大标签. 每个子项包含两个标签,一个大的,一个小的。
286- |getSmallLabelAt|获取位于 position 的小标签. 每个子项包含两个标签,一个大的,一个小的。
287- |getMenuItemPosition|获取子菜单的索引。如果找不到,返回 -1。
288- |getOnNavigationItemSelectedListener|获取 OnNavigationItemSelectedListener。
289- |setCurrentItem|设置当前选中项。
290- |setIconMarginTop|设置 icon 的 MarginTop,用于调节图标垂直位置。
291- |setIconSize|设置所有的子项图标大小。
292- |setIconSizeAt|设置位于 position 的图标的大小。
293- |setIconsMarginTop|设置所有 icon 的 MarginTop,用于调节图标垂直位置。
294- |setIconTintList| 设置图片的渲染颜色列表(Selector)
295- |setIconVisibility|设置图片可见性。
296- |setItemBackground| 设置子项的背景。
297- |setItemHeight|设置子项高度。
298- |setLargeTextSize|设置所有子项的大标签文本大小。每个子项有两个标签,一个大的,一个小的。当子项未选中时,显示小标签;选中时,显示大标签。
299- |setSmallTextSize|设置所有子项的小标签文本大小。每个子项有两个标签,一个大的,一个小的。当子项未选中时,显示小标签;选中时,显示大标签。
300- |setTextSize|设置所有子项的大和小标签文本大小。
301- |setTextVisibility|设置文本可见性。
302- |setTypeface|设置所有子项的 TextView 字体
303- |setupWithViewPager|和 ViewPager 绑定,当 任何一个选中项改变时,都会自动改变另一项。
304-
305-
306- ## 例子 ##
307-
308- ** 样式**
309-
310- ![ ] ( /read_me_images/normal.gif )
311-
312- ![ ] ( /read_me_images/no_animation.gif )
313-
314- ![ ] ( /read_me_images/no_shifting_mode.gif )
315-
316- ![ ] ( /read_me_images/no_item_shifting_mode.gif )
317-
318- ![ ] ( /read_me_images/no_text.gif )
319-
320- ![ ] ( /read_me_images/no_icon.gif )
321-
322- ![ ] ( /read_me_images/no_animation_shifting_mode.gif )
323-
324- ![ ] ( /read_me_images/no_animation_item_shifting_mode.gif )
325-
326- ![ ] ( /read_me_images/no_animation_shifting_mode_item_shifting_mode.gif )
327-
328- ![ ] ( /read_me_images/no_shifting_mode_item_shifting_mode_text.gif )
329-
330- ![ ] ( /read_me_images/no_animation_shifting_mode_item_shifting_mode_text.gif )
331-
332- ![ ] ( /read_me_images/no_shifting_mode_item_shifting_mode_and_icon.gif )
333-
334- ![ ] ( /read_me_images/no_item_shifting_mode_icon.gif )
335-
336- ![ ] ( /read_me_images/no_animation_shifting_mode_item_shifting_mode_icon.gif )
337-
338- ** 注意:这个 style 在安卓 4.x 上有 bug**
339- ![ ] ( /read_me_images/with_padding.jpg )
340-
341- ![ ] ( /read_me_images/center_icon_only.jpg )
342-
343- ![ ] ( /read_me_images/smaller_text.jpg )
344-
345- ![ ] ( /read_me_images/bigger_icon.jpg )
346-
347- ![ ] ( /read_me_images/custom_typeface.jpg )
348-
349- ![ ] ( /read_me_images/icon_selector_1.jpg ) ![ ] ( /read_me_images/icon_selector_2.jpg )
350-
351- ![ ] ( /read_me_images/icon_margin_top.jpg )
352-
353- ** 和 ViewPager 一起使用**
354-
355- ![ ] ( /read_me_images/with_view_pager.gif )
356-
357- ** 带数字的小红圈**
358-
359- ![ ] ( /read_me_images/view_badger.gif )
360-
361- ## 加入工程 ##
362-
363- ### Sdk 版本 ###
364- ` compileSdkVersion ` >= 25
365-
366- ### 导入本库 ###
367-
368- #### Gradle例子: ####
369-
370- 步骤 1. 在工程根目录的 ` build.gradle ` 最后添加如下代码:
371- ``` groovy
372- allprojects {
373- repositories {
374- ...
375- maven { url "https://jitpack.io" }
376- }
377- }
378- ```
379-
380- 步骤 2. 添加依赖
381- ``` groovy
382- compile 'com.github.ittianyu:BottomNavigationViewEx:1.1.9'
383- ```
384-
385- #### 手动导入: ####
386-
387- 下载文件 [ BottomNavigationViewEx.java] ( https://raw.githubusercontent.com/ittianyu/BottomNavigationViewEx/master/widget/src/main/java/com/ittianyu/bottomnavigationviewex/BottomNavigationViewEx.java ) 并复制到你的工程中。
388-
389-
390- ## 开始使用 ##
391-
392-
393- 在 ` xml ` 布局中添加自定义控件:
394- ``` xml
395- <com .ittianyu.bottomnavigationviewex.BottomNavigationViewEx
396- android : id =" @+id/bnve"
397- android : layout_width =" match_parent"
398- android : layout_height =" wrap_content"
399- android : layout_alignParentBottom =" true"
400- android : background =" @color/colorPrimary"
401- app : itemIconTint =" @color/selector_item_color"
402- app : itemTextColor =" @color/selector_item_color"
403- app : menu =" @menu/menu_navigation_with_view_pager" />
404- ```
405-
406- 在 ` Activity ` 中绑定控件:
407- ``` java
408- BottomNavigationViewEx bnve = (BottomNavigationViewEx ) findViewById(R . id. bnve);
409- ```
410-
411- #### 禁止所有动画效果 ####
412- ``` java
413- bnve. enableAnimation(false );
414- bnve. enableShiftingMode(false );
415- bnve. enableItemShiftingMode(false );
416- ```
417-
418- #### 自定义图标和文本大小 ####
419- ``` java
420- bnve. setIconSize(widthDp, heightDp);
421- bnve. setTextSize(sp);
422- ```
423-
424- #### 和 ViewPager 绑定####
425- ``` java
426- // set adapter
427- adapter = new VpAdapter (getSupportFragmentManager(), fragments);
428- bind. vp. setAdapter(adapter);
429-
430- // binding with ViewPager
431- bind. bnve. setupWithViewPager(bind. vp);
432- ```
433-
434-
435- #### 添加带数字的小红点 ####
436-
437- 1 . Gradle 中加入 badge 库的依赖
438- ```
439- compile 'q.rorbin:badgeview:1.1.0'
440- ```
441- 2 . 和底部控件绑定
442- ```
443- // add badge
444- addBadgeAt(2, 1);
445-
446- private Badge addBadgeAt(int position, int number) {
447- // add badge
448- return new QBadgeView(this)
449- .setBadgeNumber(number)
450- .setGravityOffset(12, 2, true)
451- .bindTarget(bind.bnve.getBottomNavigationItemView(position))
452- .setOnDragStateChangedListener(new Badge.OnDragStateChangedListener() {
453- @Override
454- public void onDragStateChanged(int dragState, Badge badge, View targetView) {
455- if (Badge.OnDragStateChangedListener.STATE_SUCCEED == dragState)
456- Toast.makeText(BadgeViewActivity.this, R.string.tips_badge_removed, Toast.LENGTH_SHORT).show();
457- }
458- });
459- }
460- ```
461-
462- #### 其他 BottomNavigationViewEx 的用法 ####
463- 请参考demo。
464-
465- #### 其他 BottomNavigationView 的用法 ####
466- 其他用法和官方 ` BottomNavigationView ` 一样。
467- 详情[ 点击这里] ( https://developer.android.com/reference/android/support/design/widget/BottomNavigationView.html )
468-
469-
470- ## 混淆 ##
471-
472- 如果你启用了 ProGuard,那你应该加上以下混淆代码:
473- ```
474- -keep public class android.support.design.widget.BottomNavigationView { *; }
475- -keep public class android.support.design.internal.BottomNavigationMenuView { *; }
476- -keep public class android.support.design.internal.BottomNavigationPresenter { *; }
477- -keep public class android.support.design.internal.BottomNavigationItemView { *; }
478- ```
479-
480-
481- ## 来源 ##
482-
483- 本库修改自安卓官方 ` Support Library 25 design ` 中的 ` BottomNavigationView ` 。
484-
485- 我在尝试使用官方的库时,发现缺少灵活性。比如官方并没有提供切换当前选中项的方法。所以我在此基础上包装了一层,对外公开了一些方法。
486-
487- 你完全没有必要担心库的稳定性,因为我是使用反射对父类进行最小限度的修改。
488-
489- ## 致谢 ##
490-
491- 感谢 [ Adrián Mouly] ( https://github.com/amouly ) | [ liaolintao] ( https://github.com/liaolintao ) .
492-
493- ## 授权 ##
494-
495- MIT License
496-
497- Copyright (c) 2017 ittianyu
498-
499- Permission is hereby granted, free of charge, to any person obtaining a copy
500- of this software and associated documentation files (the "Software"), to deal
501- in the Software without restriction, including without limitation the rights
502- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
503- copies of the Software, and to permit persons to whom the Software is
504- furnished to do so, subject to the following conditions:
505-
506- The above copyright notice and this permission notice shall be included in all
507- copies or substantial portions of the Software.
508-
509- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
510- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
511- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
512- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
513- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
514- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
515- SOFTWARE.
0 commit comments