How can I disable a tab?
I want to disable a tab so nothing will happen when the user taps on it. The library doesn't give you access to tab items after they have been set, so how can it be done?
It isn't supported right away. Everything that should happen when a tab gets selected needs to be implemented by you. So you only need to not perform the action when a "disabled tab" is selected. In order that the bottombar reflects the correct state, the following workaround works:
- Register an OnTabClickListener listener
- Whenever a tab got selected, store the position of that tab into a variable in your activity
- When the tab that you consider disabled is selected, call
mBottomBar.selectTabAtPosition(currentBottomBarTabIndex);, whereby currentBottomBarTabIndex refers to the tab that was opened when the user pressed the "disabled tab".
Indeed. This seems the best solution at the moment. Still, perhaps I should had been more explicit, my question was more about how to change a tab's appearance to look disabled (icon & text color), as these resources are defined when the bottom bar is instantiated.
On the new version (2.0) I tried the above workaround (which was working on version 1.4), however it doesn't work anymore. I had to use a Handler and do postDelayed with about 300ms to get it to work.
https://stackoverflow.com/a/19464718/6325722
Check the answer of Parag Chauhan. Worked prefectly. (Disable view and recursively disable all inner views).
public static void enableDisableView(View view, boolean enabled) {
view.setEnabled(enabled);
if ( view instanceof ViewGroup ) {
ViewGroup group = (ViewGroup)view;
for ( int idx = 0 ; idx < group.getChildCount() ; idx++ ) {
enableDisableView(group.getChildAt(idx), enabled);
}
}
}