diff --git a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java index c29ec368..20b451d3 100644 --- a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java +++ b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java @@ -422,6 +422,27 @@ public void selectTabAtPosition(int position, boolean animate) { shiftingMagic(oldTab, newTab, animate); } + /** + * Unselect a tab at the specified position. + * + * @param position the position to unselect. + */ + public void unselectTabAtPosition(int position, boolean animate) { + if (mItems == null || mItems.length == 0) { + throw new UnsupportedOperationException("Can't select tab at " + + "position " + position + ". This BottomBar has no items set yet."); + } else if (position > mItems.length - 1 || position < 0) { + throw new IndexOutOfBoundsException("Can't select tab at position " + + position + ". This BottomBar has no items at that position."); + } + + View tab = mItemContainer.getChildAt(position); + + unselectTab(tab, animate); + + updateSelectedTab(position); + } + /** * Sets the default tab for this BottomBar that is shown until the user changes * the selection. @@ -1067,10 +1088,15 @@ private void handleClick(View v) { if (v.getTag().equals(TAG_BOTTOM_BAR_VIEW_INACTIVE)) { View oldTab = findViewWithTag(TAG_BOTTOM_BAR_VIEW_ACTIVE); - unselectTab(oldTab, true); + if (oldTab != null) { + unselectTab(oldTab, true); + } + selectTab(v, true); - shiftingMagic(oldTab, v, true); + if (oldTab != null) { + shiftingMagic(oldTab, v, true); + } } updateSelectedTab(findItemPosition(v)); } diff --git a/build.gradle b/build.gradle index 07886877..607c16ad 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.0' + classpath 'com.android.tools.build:gradle:2.1.2' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'