diff --git a/README.md b/README.md
index 82b251e..75c6009 100644
--- a/README.md
+++ b/README.md
@@ -27,8 +27,10 @@ An android lib for enhancing BottomNavigationView.
|getMenuItemPosition|Get menu item position in menu. Return position if success, -1 otherwise.
|getOnNavigationItemSelectedListener|Get OnNavigationItemSelectedListener.
|setCurrentItem|Set the current checked item.
+|setIconMarginTop|set margin top for icon.
|setIconSize|Set all item ImageView size.
|setIconSizeAt|Set all item ImageView size which at position.
+|setIconsMarginTop|set margin top for all icons.
|setIconTintList| Set the icon tint list.
|setIconVisibility|Change the visibility of icon.
|setItemBackground| Set background of item.
@@ -73,6 +75,7 @@ An android lib for enhancing BottomNavigationView.
![](/read_me_images/no_animation_shifting_mode_item_shifting_mode_icon.gif)
+**Attention: Something wrong on Android 4.x**
![](/read_me_images/with_padding.jpg)
![](/read_me_images/center_icon_only.jpg)
@@ -85,6 +88,9 @@ An android lib for enhancing BottomNavigationView.
![](/read_me_images/icon_selector_1.jpg) ![](/read_me_images/icon_selector_2.jpg)
+![](/read_me_images/icon_margin_top.jpg)
+
+
**With ViewPager**
![](/read_me_images/with_view_pager.gif)
@@ -114,12 +120,12 @@ allprojects {
Step 2. Add the dependency
```groovy
-compile 'com.github.ittianyu:BottomNavigationViewEx:1.1.8'
+compile 'com.github.ittianyu:BottomNavigationViewEx:1.1.9'
```
#### Manual: ####
-Downloading [BottomNavigationViewEx.java](https://raw.githubusercontent.com/ittianyu/BottomNavigationViewEx/master/widget/src/main/java/com/ittianyu/bottomnavigationviewex/BottomNavigationViewEx.java) and copying it to you project。
+Downloading [BottomNavigationViewEx.java](https://raw.githubusercontent.com/ittianyu/BottomNavigationViewEx/master/widget/src/main/java/com/ittianyu/bottomnavigationviewex/BottomNavigationViewEx.java) and copying it to you project.
## Getting started ##
@@ -254,8 +260,10 @@ Thanks for [Adrián Mouly](https://github.com/amouly) | [liaolintao](https://git
|getMenuItemPosition|获取子菜单的索引。如果找不到,返回 -1。
|getOnNavigationItemSelectedListener|获取 OnNavigationItemSelectedListener。
|setCurrentItem|设置当前选中项。
+|setIconMarginTop|设置 icon 的 MarginTop,用于调节图标垂直位置。
|setIconSize|设置所有的子项图标大小。
|setIconSizeAt|设置位于 position 的图标的大小。
+|setIconsMarginTop|设置所有 icon 的 MarginTop,用于调节图标垂直位置。
|setIconTintList| 设置图片的渲染颜色列表(Selector)
|setIconVisibility|设置图片可见性。
|setItemBackground| 设置子项的背景。
@@ -300,6 +308,7 @@ Thanks for [Adrián Mouly](https://github.com/amouly) | [liaolintao](https://git
![](/read_me_images/no_animation_shifting_mode_item_shifting_mode_icon.gif)
+**注意:这个 style 在安卓 4.x 上有 bug**
![](/read_me_images/with_padding.jpg)
![](/read_me_images/center_icon_only.jpg)
@@ -312,6 +321,8 @@ Thanks for [Adrián Mouly](https://github.com/amouly) | [liaolintao](https://git
![](/read_me_images/icon_selector_1.jpg) ![](/read_me_images/icon_selector_2.jpg)
+![](/read_me_images/icon_margin_top.jpg)
+
**和 ViewPager 一起使用**
![](/read_me_images/with_view_pager.gif)
@@ -341,7 +352,7 @@ allprojects {
步骤 2. 添加依赖
```groovy
-compile 'com.github.ittianyu:BottomNavigationViewEx:1.1.8'
+compile 'com.github.ittianyu:BottomNavigationViewEx:1.1.9'
```
#### 手动导入: ####
diff --git a/app/build.gradle b/app/build.gradle
index 927b012..7c94f76 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -8,8 +8,8 @@ android {
applicationId "com.ittianyu.bottomnavigationviewexsample"
minSdkVersion 9
targetSdkVersion rootProject.ext.targetSdkVersion
- versionCode 12
- versionName "1.1.8"
+ versionCode 13
+ versionName "1.1.9"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
diff --git a/app/src/main/java/com/ittianyu/bottomnavigationviewexsample/features/style/StyleActivity.java b/app/src/main/java/com/ittianyu/bottomnavigationviewexsample/features/style/StyleActivity.java
index 27d83cc..33b7591 100644
--- a/app/src/main/java/com/ittianyu/bottomnavigationviewexsample/features/style/StyleActivity.java
+++ b/app/src/main/java/com/ittianyu/bottomnavigationviewexsample/features/style/StyleActivity.java
@@ -81,8 +81,11 @@ private void init() {
initCustomTypeface();
bind.bnveIconSelector.enableAnimation(false);
+
+ initMargin();
}
+
private void initCenterIconOnly() {
bind.bnveCenterIconOnly.enableAnimation(false);
bind.bnveCenterIconOnly.enableShiftingMode(false);
@@ -94,7 +97,7 @@ private void initCenterIconOnly() {
bind.bnveCenterIconOnly.setItemBackground(centerPosition, R.color.colorGreen);
bind.bnveCenterIconOnly.setIconTintList(centerPosition,
getResources().getColorStateList(R.color.selector_item_gray_color));
- bind.bnveCenterIconOnly.setIconCenter(centerPosition);
+ bind.bnveCenterIconOnly.setIconMarginTop(centerPosition, BottomNavigationViewEx.dp2px(this, 4));
// you could set a listener for bnve. and return false when click the center item so that it won't be checked.
bind.bnveCenterIconOnly.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
@@ -140,4 +143,13 @@ private void initCustomTypeface() {
// bind.bnveCustomTypeface.setTypeface(typeface);
}
+ private void initMargin() {
+ bind.bnveIconMarginTop.enableAnimation(false);
+ bind.bnveIconMarginTop.enableShiftingMode(false);
+ bind.bnveIconMarginTop.enableItemShiftingMode(false);
+ bind.bnveIconMarginTop.setTextVisibility(false);
+ bind.bnveIconMarginTop.setItemHeight(BottomNavigationViewEx.dp2px(this, 56));
+ bind.bnveIconMarginTop.setIconsMarginTop(BottomNavigationViewEx.dp2px(this, 16));
+ }
+
}
diff --git a/app/src/main/res/layout/activity_style.xml b/app/src/main/res/layout/activity_style.xml
index 1d3cd5a..cbd9deb 100644
--- a/app/src/main/res/layout/activity_style.xml
+++ b/app/src/main/res/layout/activity_style.xml
@@ -236,6 +236,17 @@
app:itemTextColor="@color/selector_item_primary_color"
app:menu="@menu/menu_navigation_selector" />
+
- * It will go back when it was checked {@code android.support.design.internal.BottomNavigationItemView#setChecked()} - * So you need call {@link #enableShiftingMode(int, boolean)} to make it center again when item selected - *
- * + * set margin top for all icons + * @param marginTop in px + */ + public void setIconsMarginTop(int marginTop) { + for (int i = 0; i < getItemCount(); i++) { + setIconMarginTop(i, marginTop); + } + } + + /** + * set margin top for icon * @param position + * @param marginTop in px */ - public void setIconCenter(int position) { - enableShiftingMode(position, true); - ImageView iv = getIconAt(position); - FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) iv.getLayoutParams(); - lp.gravity = Gravity.CENTER; + public void setIconMarginTop(int position, int marginTop) { + /* + 1. BottomNavigationItemView + 2. private final int mDefaultMargin; + */ + BottomNavigationItemView itemView = getBottomNavigationItemView(position); + setField(BottomNavigationItemView.class, itemView, "mDefaultMargin", marginTop); + mMenuView.updateMenuView(); } }