BottomBar icon indicating copy to clipboard operation
BottomBar copied to clipboard

How can I disable a tab?

Open cristian-rosu opened this issue 9 years ago • 4 comments

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?

cristian-rosu avatar Jul 07 '16 11:07 cristian-rosu

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".

Nolanus avatar Jul 17 '16 13:07 Nolanus

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.

cristian-rosu avatar Jul 17 '16 17:07 cristian-rosu

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.

teoinke avatar Dec 09 '16 02:12 teoinke

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);
            }
        }
    }

johnnyfivedev avatar Nov 23 '17 08:11 johnnyfivedev