I am developing a application in which i am using Tab host without fragment. I want to remove action bar in particular Tab2Activity(Tab1 Tab2 Tab3).
Asked
Active
Viewed 932 times
3 Answers
2
The Tabs start from 0 and goes 0, 1, 2, 3...
If you're selecting Tab 1 use Tab 0.
@Override
public void onTabSelected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
// When the given tab is selected, switch to the corresponding page in
// the ViewPager.
mViewPager.setCurrentItem(tab.getPosition());
if (tab.getPosition() == 0) {
Toast tab1SelectedToast = Toast.makeText(this, "Tab 1 Selected", Toast.LENGTH_LONG);
tab1SelectedToast.show();
ActionBar actionBar = getActionBar();
actionBar.hide();
} else {
ActionBar actionBar = getActionBar();
actionBar.show();
}
}

Adam
- 50
- 1
- 7
-
My apologies. If that's the case, using OnTabChangeListener would do the trick. Using Nil's code to listen to Tab changes and hide it with `ActionBar actionBar = getActionBar(); actionBar.show();` – Adam Jan 24 '14 at 11:35
1
Make the activity listen to tab changed, when changed ask tab if you should hide the action bar by adding a method and some interface, if the current tab returns true, hide the action bar, else show it.

Chen Kinnrot
- 20,609
- 17
- 79
- 141
1
try this..
getTabHost().setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
int i = getTabHost().getCurrentTab();
Log.i("@@@@@@@@ ANN CLICK TAB NUMBER", "------" + i);
if (i == 0) {
Log.i("@@@@@@@@@@ Inside onClick tab 0", "onClick tab");
} else if (i == 1) {
Log.i("@@@@@@@@@@ Inside onClick tab 1", "onClick tab");
}
}
});

Born To Win
- 3,319
- 3
- 19
- 27