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 350cc316..411e02e2 100644 --- a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java +++ b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java @@ -543,6 +543,16 @@ public void selectTabAtPosition(int position) { selectTabAtPosition(position, false); } + public void selectOnlyWithId(@IdRes final int tabResId) { + final int tabPosition = findPositionForTabWithId(tabResId); + selectTabAtPosition(tabPosition, false, true); + } + + + public void selectOnlyAtPosition(final int position) { + selectTabAtPosition(position, false, true); + } + /** * Select a tab at the specified position. * @@ -550,6 +560,10 @@ public void selectTabAtPosition(int position) { * @param animate should the tab change be animated or not. */ public void selectTabAtPosition(int position, boolean animate) { + selectTabAtPosition(position, animate, false); + } + + private void selectTabAtPosition(final int position, final boolean animate, final boolean highlightOnly) { if (position > getTabCount() - 1 || position < 0) { throw new IndexOutOfBoundsException("Can't select tab at position " + position + ". This BottomBar has no items at that position."); @@ -561,7 +575,7 @@ public void selectTabAtPosition(int position, boolean animate) { oldTab.deselect(animate); newTab.select(animate); - updateSelectedTab(position); + updateSelectedTab(position, highlightOnly); shiftingMagic(oldTab, newTab, animate); handleBackgroundColorChange(newTab, animate); } @@ -941,15 +955,21 @@ private boolean handleLongClick(BottomBarTab longClickedTab) { return true; } - private void updateSelectedTab(int newPosition) { + private void updateSelectedTab(final int newPosition) { + updateSelectedTab(newPosition, false); + } + + private void updateSelectedTab(final int newPosition, final boolean highlightOnly) { int newTabId = getTabAtPosition(newPosition).getId(); - if (newPosition != currentTabPosition) { - if (onTabSelectListener != null) { - onTabSelectListener.onTabSelected(newTabId); + if (!highlightOnly) { + if (newPosition != currentTabPosition) { + if (onTabSelectListener != null) { + onTabSelectListener.onTabSelected(newTabId); + } + } else if (onTabReselectListener != null && !ignoreTabReselectionListener) { + onTabReselectListener.onTabReSelected(newTabId); } - } else if (onTabReselectListener != null && !ignoreTabReselectionListener) { - onTabReselectListener.onTabReSelected(newTabId); } currentTabPosition = newPosition;