diff --git a/README.md b/README.md
index f202d5c9..8e883006 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ Library to implement the Bottom Navigation component from Material Design guidel
## Demo
-
+
## What's new (2.0.6) - [Changelog](https://github.com/aurelhubert/ahbottomnavigation/blob/master/CHANGELOG.md)
* Fix selected item background for API >= 21
* Fix `isHidden()` method
@@ -124,6 +124,12 @@ bottomNavigation.setOnNavigationPositionListener(new AHBottomNavigation.OnNaviga
// Manage the new y position
}
});
+
+// Set BottomBorder Line Or Radius
+bottomNavigation.setNavigationBorderLine(iColor,iRadius,rShapePading);
+// OR use default border line style: #a1a1a1 iRadius=0 new Rect(0,2,0,0)
+bottomNavigation.setNavigationBorderLine();
+
```
### With XML menu
diff --git a/ahbottomnavigation/build.gradle b/ahbottomnavigation/build.gradle
index b92b37b1..22b71238 100644
--- a/ahbottomnavigation/build.gradle
+++ b/ahbottomnavigation/build.gradle
@@ -26,7 +26,7 @@ ext {
android {
compileSdkVersion 25
- buildToolsVersion '25.0.2'
+ buildToolsVersion '25.0.3'
defaultConfig {
minSdkVersion 14
@@ -43,7 +43,7 @@ android {
}
dependencies {
- compile 'com.android.support:design:25.2.0'
+ compile 'com.android.support:design:25.3.1'
}
// Place it at the end of the file
diff --git a/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigation.java b/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigation.java
index 0d91f7d9..b35a7435 100644
--- a/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigation.java
+++ b/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHBottomNavigation.java
@@ -7,8 +7,11 @@
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Color;
+import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
+import android.graphics.drawable.GradientDrawable;
+import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
@@ -117,6 +120,10 @@ public enum TitleState {
private int notificationActiveMarginLeft, notificationInactiveMarginLeft;
private int notificationActiveMarginTop, notificationInactiveMarginTop;
+ // bottom line
+ private @ColorInt int bottomNavigationBorderLineColor;
+ private @ColorInt int bottomNavigationBorderLineRadius=0;
+ private Rect bottomNavigationShapePading = new Rect(0,0,0,0);
/**
* Constructors
*/
@@ -219,6 +226,10 @@ private void init(Context context, AttributeSet attrs) {
notificationActiveMarginTop = (int) resources.getDimension(R.dimen.bottom_navigation_notification_margin_top_active);
notificationInactiveMarginTop = (int) resources.getDimension(R.dimen.bottom_navigation_notification_margin_top);
+ // bottom line
+ bottomNavigationBorderLineColor = ContextCompat.getColor(context, R.color.colorBottomNavigationShapLine);
+ bottomNavigationBorderLineRadius = 0;
+
ViewCompat.setElevation(this, resources.getDimension(R.dimen.bottom_navigation_elevation));
setClipToPadding(false);
@@ -272,6 +283,35 @@ public void run() {
});
}
+ public void setNavigationBorderLine(){
+// bottomNavigationLineColor = R.color.colorBottomNavigationNotification;
+ setNavigationBorderLine(getResources().getColor(R.color.colorBottomNavigationShapLine),0,new Rect(0,2,0,0));
+ }
+ public void setNavigationBorderLine(@ColorInt int iColor,int iRadius,Rect rShapePading){
+ bottomNavigationBorderLineColor = iColor;
+ bottomNavigationBorderLineRadius = iRadius;
+ bottomNavigationShapePading.set(rShapePading);
+// createItems();
+ setLayerDrawable(defaultBackgroundColor);
+ }
+
+ private void setLayerDrawable(@ColorInt int bgcolor){
+ GradientDrawable whiteDrawable = getGradientDrawable(getContext(), bgcolor, bottomNavigationBorderLineRadius);//getResources().getColor(android.R.color.transparent)
+ GradientDrawable grayDrawable = getGradientDrawable(getContext(), bottomNavigationBorderLineColor, bottomNavigationBorderLineRadius);
+ LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{grayDrawable, whiteDrawable});
+ //设置padding
+ layerDrawable.setLayerInset(0, 0, 0, 0, 0);
+ layerDrawable.setLayerInset(1, bottomNavigationShapePading.left, bottomNavigationShapePading.top, bottomNavigationShapePading.right, bottomNavigationShapePading.bottom);
+
+ ViewCompat.setBackground(this,layerDrawable);
+ }
+ public static GradientDrawable getGradientDrawable(Context context,@ColorInt int colID, int dp) {
+ GradientDrawable drawable = new GradientDrawable();
+ drawable.setColor(colID);
+ drawable.setCornerRadius(dp);
+ return drawable;
+ }
+
@SuppressLint("NewApi")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private int calculateHeight(int layoutHeight) {
@@ -423,13 +463,15 @@ private void createClassicItems(LinearLayout linearLayout) {
if (colored) {
if (current) {
setBackgroundColor(item.getColor(context));
+ setLayerDrawable(item.getColor(context));
currentColor = item.getColor(context);
}
} else {
if (defaultBackgroundResource != 0) {
setBackgroundResource(defaultBackgroundResource);
} else {
- setBackgroundColor(defaultBackgroundColor);
+// setBackgroundColor(defaultBackgroundColor);
+ setLayerDrawable(defaultBackgroundColor);
}
}
@@ -540,14 +582,16 @@ private void createSmallItems(LinearLayout linearLayout) {
if (colored) {
if (i == currentItem) {
- setBackgroundColor(item.getColor(context));
+// setBackgroundColor(item.getColor(context));
+ setLayerDrawable(item.getColor(context));
currentColor = item.getColor(context);
}
} else {
if (defaultBackgroundResource != 0) {
setBackgroundResource(defaultBackgroundResource);
} else {
- setBackgroundColor(defaultBackgroundColor);
+// setBackgroundColor(defaultBackgroundColor);
+ setLayerDrawable(defaultBackgroundColor);
}
}
@@ -640,9 +684,9 @@ private void updateItems(final int itemIndex, boolean useCallback) {
int cy = view.getHeight() / 2;
if (circleRevealAnim != null && circleRevealAnim.isRunning()) {
- circleRevealAnim.cancel();
- setBackgroundColor(items.get(itemIndex).getColor(context));
+ circleRevealAnim.cancel();
backgroundColorView.setBackgroundColor(Color.TRANSPARENT);
+ setLayerDrawable(items.get(itemIndex).getColor(context));
}
circleRevealAnim = ViewAnimationUtils.createCircularReveal(backgroundColorView, cx, cy, 0, finalRadius);
@@ -654,9 +698,9 @@ public void onAnimationStart(Animator animation) {
}
@Override
- public void onAnimationEnd(Animator animation) {
- setBackgroundColor(items.get(itemIndex).getColor(context));
+ public void onAnimationEnd(Animator animation) {
backgroundColorView.setBackgroundColor(Color.TRANSPARENT);
+ setLayerDrawable(items.get(itemIndex).getColor(context));
}
@Override
@@ -670,12 +714,17 @@ public void onAnimationRepeat(Animator animation) {
circleRevealAnim.start();
} else if (colored) {
AHHelper.updateViewBackgroundColor(this, currentColor,
- items.get(itemIndex).getColor(context));
+ items.get(itemIndex).getColor(context), new AHHelper.AHBgAnimation() {
+ @Override
+ public void backGroundColorAnimation(int color) {
+ setLayerDrawable(color);
+ }
+ });
} else {
if (defaultBackgroundResource != 0) {
setBackgroundResource(defaultBackgroundResource);
- } else {
- setBackgroundColor(defaultBackgroundColor);
+ } else {
+ setLayerDrawable(defaultBackgroundColor);
}
backgroundColorView.setBackgroundColor(Color.TRANSPARENT);
}
@@ -702,8 +751,8 @@ public void onAnimationRepeat(Animator animation) {
} else if (currentItem == CURRENT_ITEM_NONE) {
if (defaultBackgroundResource != 0) {
setBackgroundResource(defaultBackgroundResource);
- } else {
- setBackgroundColor(defaultBackgroundColor);
+ } else {
+ setLayerDrawable(defaultBackgroundColor);
}
backgroundColorView.setBackgroundColor(Color.TRANSPARENT);
}
@@ -766,8 +815,8 @@ private void updateSmallItems(final int itemIndex, boolean useCallback) {
int cy = views.get(itemIndex).getHeight() / 2;
if (circleRevealAnim != null && circleRevealAnim.isRunning()) {
- circleRevealAnim.cancel();
- setBackgroundColor(items.get(itemIndex).getColor(context));
+ circleRevealAnim.cancel();
+ setLayerDrawable(items.get(itemIndex).getColor(context));
backgroundColorView.setBackgroundColor(Color.TRANSPARENT);
}
@@ -780,8 +829,8 @@ public void onAnimationStart(Animator animation) {
}
@Override
- public void onAnimationEnd(Animator animation) {
- setBackgroundColor(items.get(itemIndex).getColor(context));
+ public void onAnimationEnd(Animator animation) {
+ setLayerDrawable(items.get(itemIndex).getColor(context));
backgroundColorView.setBackgroundColor(Color.TRANSPARENT);
}
@@ -796,12 +845,17 @@ public void onAnimationRepeat(Animator animation) {
circleRevealAnim.start();
} else if (colored) {
AHHelper.updateViewBackgroundColor(this, currentColor,
- items.get(itemIndex).getColor(context));
+ items.get(itemIndex).getColor(context), new AHHelper.AHBgAnimation() {
+ @Override
+ public void backGroundColorAnimation(int color) {
+ setLayerDrawable(color);
+ }
+ });
} else {
if (defaultBackgroundResource != 0) {
setBackgroundResource(defaultBackgroundResource);
- } else {
- setBackgroundColor(defaultBackgroundColor);
+ } else {
+ setLayerDrawable(defaultBackgroundColor);
}
backgroundColorView.setBackgroundColor(Color.TRANSPARENT);
}
@@ -835,8 +889,8 @@ public void onAnimationRepeat(Animator animation) {
} else if (currentItem == CURRENT_ITEM_NONE) {
if (defaultBackgroundResource != 0) {
setBackgroundResource(defaultBackgroundResource);
- } else {
- setBackgroundColor(defaultBackgroundColor);
+ } else {
+ setLayerDrawable(defaultBackgroundColor);
}
backgroundColorView.setBackgroundColor(Color.TRANSPARENT);
}
diff --git a/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHHelper.java b/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHHelper.java
index 46c08a5c..cd5a49fe 100644
--- a/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHHelper.java
+++ b/ahbottomnavigation/src/main/java/com/aurelhubert/ahbottomnavigation/AHHelper.java
@@ -24,6 +24,12 @@
*/
public class AHHelper {
+
+ public interface AHBgAnimation{
+ public void backGroundColorAnimation(@ColorInt int color);
+ }
+
+
/**
* Return a tint drawable
*
@@ -168,6 +174,21 @@ public void onAnimationUpdate(ValueAnimator animator) {
colorAnimation.start();
}
+ public static void updateViewBackgroundColor(final View view, @ColorInt int fromColor,
+ @ColorInt int toColor ,final AHBgAnimation ahBganimal) {
+ ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), fromColor, toColor);
+ colorAnimation.setDuration(150);
+ colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator animator) {
+ if(ahBganimal != null){
+ ahBganimal.backGroundColorAnimation((Integer) animator.getAnimatedValue());
+ }
+ }
+ });
+ colorAnimation.start();
+ }
+
/**
* Update image view color with animation
*/
diff --git a/ahbottomnavigation/src/main/res/values/colors.xml b/ahbottomnavigation/src/main/res/values/colors.xml
index bc757bcc..964bc9a5 100644
--- a/ahbottomnavigation/src/main/res/values/colors.xml
+++ b/ahbottomnavigation/src/main/res/values/colors.xml
@@ -8,4 +8,5 @@
#50FFFFFF
#17000000
#F63D2B
+ #d8d8d8
diff --git a/ahbottomnavigation/src/main/res/values/dimens.xml b/ahbottomnavigation/src/main/res/values/dimens.xml
index 2c632bbd..a7077463 100644
--- a/ahbottomnavigation/src/main/res/values/dimens.xml
+++ b/ahbottomnavigation/src/main/res/values/dimens.xml
@@ -43,5 +43,4 @@
14dp
3dp
9sp
-
diff --git a/build.gradle b/build.gradle
index 99186f46..6e5ee7b7 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.3.0'
+ classpath 'com.android.tools.build:gradle:2.4.+'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
diff --git a/demo/build.gradle b/demo/build.gradle
index 1f09bc76..32b02adb 100644
--- a/demo/build.gradle
+++ b/demo/build.gradle
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 25
- buildToolsVersion '25.0.2'
+ buildToolsVersion '25.0.3'
defaultConfig {
applicationId "com.aurelhubert.ahbottomnavigation.demo"
@@ -24,8 +24,8 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
- compile 'com.android.support:appcompat-v7:25.0.0'
- compile 'com.android.support:cardview-v7:25.0.0'
- compile 'com.android.support:design:25.0.0'
+ compile 'com.android.support:appcompat-v7:25.3.1'
+ compile 'com.android.support:cardview-v7:25.3.1'
+ compile 'com.android.support:design:25.3.1'
compile project(':ahbottomnavigation')
}
diff --git a/demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoActivity.java b/demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoActivity.java
index e94522bf..8b50945e 100644
--- a/demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoActivity.java
+++ b/demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoActivity.java
@@ -3,8 +3,10 @@
import android.animation.Animator;
import android.content.Context;
import android.content.Intent;
+import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
+import android.support.annotation.ColorInt;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
@@ -283,6 +285,14 @@ public void setForceTitleHide(boolean forceTitleHide) {
bottomNavigation.setTitleState(state);
}
+ /**
+ * Show BorderLine
+ * default setBottomLine()
+ */
+ public void setNavigationBorderLine(@ColorInt int iColor, int iRadius, Rect rShapePading) {
+ bottomNavigation.setNavigationBorderLine(iColor,iRadius,rShapePading);
+ }
+
/**
* Reload activity
*/
diff --git a/demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoFragment.java b/demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoFragment.java
index 969174d4..94038d6a 100644
--- a/demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoFragment.java
+++ b/demo/src/main/java/com/aurelhubert/ahbottomnavigation/demo/DemoFragment.java
@@ -1,6 +1,7 @@
package com.aurelhubert.ahbottomnavigation.demo;
import android.content.Context;
+import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
@@ -64,6 +65,7 @@ private void initDemoSettings(View view) {
final SwitchCompat showSelectedBackground = (SwitchCompat) view.findViewById(R.id.fragment_demo_selected_background);
final SwitchCompat switchForceTitleHide = (SwitchCompat) view.findViewById(R.id.fragment_demo_force_title_hide);
final SwitchCompat switchTranslucentNavigation = (SwitchCompat) view.findViewById(R.id.fragment_demo_translucent_navigation);
+ final SwitchCompat showNavigationBottomLine = (SwitchCompat) view.findViewById(R.id.fragment_demo_navigation_bottom_line);
switchColored.setChecked(demoActivity.isBottomNavigationColored());
switchFiveItems.setChecked(demoActivity.getBottomNavigationNbItems() == 5);
@@ -108,13 +110,15 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
demoActivity.updateSelectedBackgroundVisibility(isChecked);
}
});
- switchForceTitleHide.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ showNavigationBottomLine.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- demoActivity.setForceTitleHide(isChecked);
+ bShowHideBorderLine =! bShowHideBorderLine;
+ demoActivity.setNavigationBorderLine(getResources().getColor(R.color.color_tab_5),bShowHideBorderLine?5:0,new Rect(0,bShowHideBorderLine?2:0,0,0));
}
});
}
+ private boolean bShowHideBorderLine=false;
/**
* Init the fragment
diff --git a/demo/src/main/res/layout/fragment_demo_settings.xml b/demo/src/main/res/layout/fragment_demo_settings.xml
index 9f55addc..002995da 100644
--- a/demo/src/main/res/layout/fragment_demo_settings.xml
+++ b/demo/src/main/res/layout/fragment_demo_settings.xml
@@ -40,4 +40,10 @@
android:checked="false"
android:text="Enable translucent navigation" />
+
+
\ No newline at end of file
diff --git a/demo/src/main/res/values/colors.xml b/demo/src/main/res/values/colors.xml
index 0fc7207e..e61e7938 100644
--- a/demo/src/main/res/values/colors.xml
+++ b/demo/src/main/res/values/colors.xml
@@ -24,4 +24,5 @@
- #F63D2B
+ #a1a1a1
diff --git a/demo5.gif b/demo5.gif
new file mode 100644
index 00000000..c7df60f9
Binary files /dev/null and b/demo5.gif differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 40a5f768..d25182cc 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Tue Mar 07 15:39:53 CET 2017
+#Thu May 11 17:34:03 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip