It's possible to enable/disable Tabs in ActionBar? With TabHost this is not a problem.. I do:
tabHost.getTabWidget().getChildAt(3).setVisibility(true);
and all works.. but if i want to do the same thing with Tabs in ActionBar??
In Tab class don't exist setEnable();
ActionBar bar = getActionBar();
Tab tab = bar.newTab();
tab.setText("Test");
tab.setEnable(false); /*DON'T EXIST!!*/
How can I do??
I haven't tested this - that will be up to you, but it should give you an general idea on how you could handle your problem.
There are three steps:
First step
We need something that can handle the enable/disable action for us. For this purpose we create the following class:
Second step
We need something that can hold these
TabItems
and an easy way to access them. For this purpose we add the following class:Third step
We need to handle the selection of
Tabs
ourselves, so we need to create a customTabListener
:Finally
We can now utilize our created framework. To do so, we need a
TabHolder
:We need to add our
Tabs
to this:And we need to set our custom
TabListener
on eachTab
:Enable/Disable
To enable or disable a
Tab
we simply call:Let me know how it goes :)
There is a simple way to remove the Tabs-bar from the Actionbar. Just type:
This will remove any tabs-bar.
Late answer but hope this workaround might help others who are interested in this issue.
If you are using
ViewPager
with it as usual, you can simply utilize its position instead ofmLastSelectedTabIndex
like this:You could use the
removeTab( ActionBar.Tab tab )
-method ofActionBar
:And then use the
addTab( ActionBar.Tab tab, int position )
to put it back in, provided that you save the position of theTab
you removed:This is done by two simple steps(Assuming you set custom view to the tabs):
1- Disable function: Avoid changing tabs
2- Disable click events:
I tested it right now and it is working ;)
you can override:
public boolean onPrepareOptionsMenu(Menu menu)
, in here set the tab enable/disable for example:and then you can set the
mMessageNeedtoSend
true or false,callinvalidateOptionsMenu()
to refresh ActionBar.