Android - How to deselect all tabs in the ActionBar

I'm using an ActionBar with tabs in my app, along with an old fashioned menu. When you go into the fragment associated with the menu item, I'd like to keep the ActionBar visible, but deselect all the tabs.

I tried:

_actionBar.selectTab(null);

But that throws an exception.

PS I'm actually using the ActionBarSherlock for compatibility, if that makes a difference.

You could not deselect tab, what do you think will happen? One of tabs should be always selected.

Think about your users. They will not expect that behavior.

TabLayout, Remove all tabs from the action bar and deselect the current tab. C# Copy. [ Android.Runtime.Register("removeAllTabs", "()V", "GetRemoveAllTabsHandler")] � Remove all tabs from the action bar and deselect the current tab. abstract Unit removeOnMenuVisibilityListener ( listener : ActionBar.OnMenuVisibilityListener !

Then catch it :)

I just tested this, it works, the blue underline under the tab disappears which is exactly what I want to do too.

       try {
          ActionBar actionbar = (ActionBar) getActionBar();
          actionbar.selectTab(null);
       } catch (Exception e) {}

Program flow carries on....it's a work around.

how to remove tab indicator in android, Android Tabs and ActionBar Menu Items - Axway Developer Blog. is called when the Activity is created and is used to setup all the menu options. Inside this callback we need to do two things: clear the current menu and� Note: As of Android 5.0, ActionBar Tabs is now officially deprecated. Tabs should now be built using the TabLayout. Without Gingerbread Support. To setup tabs using ActionBar and fragments that are not gingerbread compatible, you need to add a TabListener implementation

How to deselect all tabs in the ActionBar

You don't. A tab is always selected.

ActionBar.RemoveAllTabs Method (Android.App), Below we remove all the tabs from the action bar and deselect the current tab. TabLayout tabLayout = (TabLayout) findViewById(R.id.simpleTabLayout); // get� abstract fun setTabListener (listener: ActionBar.TabListener!): ActionBar.Tab! Set the TabListener that will handle switching to and from this tab. All tabs must have a TabListener set before being added to the ActionBar.

I know I'm necromancing right now... but I found a solution that works. So just in case someone else is trying to do this, here you go.

You just create a dummy tab and never add it to the action bar. Select the dummy tab and the Tabs in the action bar are all NOT selected. The dummy will have an index of -1 if you debug the onTabSelected etc methods of the ActionBar.TabListener.

Note: This assumes you are implementing ActionBar.TabListener in your Activity.

String tabTitles[] = {"A", "B"};
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

for (String tabName : tabTitles) {
    actionBar.addTab(actionBar.newTab().setText(tabName).setTabListener(this), false);  
}

ActionBar.Tab dummyTab = actionBar.newTab().setText("Dummy").setTabListener(this);

try{
    actionBar.selectTab(dummnyTab);
}catch(Exception e){}

Works perfect for me.

Android Tabs and ActionBar Menu Items, Remove all tabs from the action bar and deselect the current tab. *. * @ deprecated Action bar navigation modes are deprecated and not supported by inline. public static final int NAVIGATION_MODE_TABS. This constant is deprecated. Action bar navigation modes are deprecated and not supported by inline toolbar action bars. Consider using other common navigation patterns instead. Tab navigation mode. Instead of static title text this mode presents a series of tabs for navigation within the activity.

I had a similar problem with a TabLayout. As a workaround, I first set the selected tab indicator color to transparent:

int colorTransparent = getColor(R.color.transparent);
tabLayout.setSelectedTabIndicatorColor(colorTransparent);

and hid the ViewPager/content - so it basically looked like nothing was selected with no current page visible.

Then, when the user presses the button, I changed the selected tab indicator color back to R.color.accent and faded in the ViewPager/content.

TabLayout Tutorial With Example In Android Studio, Android Contextual Action Bar - Select all / Deselect all - android. the number of items selected, then has a drop down for either Select all or Deselect all. that you expressly declared, such as the icon, title, tabs, navigation spinner, etc. Causes all threads which are waiting on this object's monitor (by means of calling one of the wait() methods) to be woken up. (Inherited from Object) RemoveAllTabs() RemoveAllTabs() Remove all tabs from the action bar and deselect the current tab.

core/java/android/app/ActionBar.java, Android developers Fragments; Android developers Action Bar; Course book The Tactics The ActionTab app will combine multiple fragments (four in all) in a single activity to The app is made up of 4 tabs and 4 corresponding fragments. the first action is to unselect the find fragment, which is currently displayed -- this� This example will show you how to use android ActionBar to implement Tab navigation. When you click one tab, it will show different content view. The system will adjusts the […]

Android Contextual Action Bar - Select all / Deselect all, Used when generating ZIP files. Theme. Light Dark Custom. Color. Show grid file_download Download ZIP. xxxhdpi. See all. xxhdpi. xhdpi. hdpi. mdpi. Introducing Tabs in the ActionBar. The action bar tries to display all of its tabs concurrently and make all the tabs equal in size based on the width of the widest tab label. This is illustrated by the following screenshot: When the ActionBar can't display all of the tabs, it will set up the tabs in a horizontally scrollable view.

Fragments and Action Bars -,

Comments
  • getActionBar().removeAllTabs();
  • No, I don't want to remove the tabs; I just don't want any of them to appear selected.
  • @K_Anas getActionBar().removeAllTabs() will just remove all tabs completely
  • OK, at least I know that's the limitation of the system. I didn't come up with the UX for this app, I'm just trying to implement the design as provided. Thanks.
  • I think he means he needs a root, with tabs on top. Selecting the tab pushes the fragment on top of the root. Root has no tabs selected. I have the same problem.
  • Clever. I will definitely try this (next time).
  • Throws a runtime exception
  • For me using the Android Support Library (and therefore using getSupportActionBar()), this threw a NullPointerException, which was then caught, but then the blue line selection bar was still there. So no Action Bar tab became unselected... Overall, nothing actually happened.
  • Works perfectly. It is probably worth pointing out that this answer is relevant to monodroid (xamarin) only. The original question is asked for native android.
  • why is this true. I have a screen for searching. I have a nearby tab, and a Favorites tab. If the user hits the search icon above it, and it brings back results, then I want neither tab selected. Yes, I could add a third tab into it. But I could also just deselect both, and to the user, it looks like expected.
  • @WallMobile: "then I want neither tab selected" -- your user does. "Yes, I could add a third tab into it" -- the user is going to think that your app has a bug if the user does a search and you do not show any results. Talented programmers, therefore, show search results when the user does a search. Either show the results in an existing tab (which should be selected), add a third tab (which should be selected), or show the results in a new activity (which has no tabs).
  • possibly. i am working throuigh what will look best for the user now. If they get back no results I would give a message. I see your point, but need to work through the process a bit to find the best user experience.
  • @WallMobile: "If they get back no results I would give a message" -- a crouton is one way to represent that, in a way that does not have to permanently disrupt the rest of your UI structure. github.com/keyboardsurfer/Crouton and johnkil.github.io/Android-AppMsg are popular solutions.
  • thanks, update your post so that i can remove the -1. got a little trigger happy :) I think I am going to go with the open a new activity route.