Im using action bar sherlock and in landscape mode all of my tabs show, but in portrait only one shows.
How can I show all tabs so the user can slide along them? They dont have to be on screen at the same time, I just dont want a pop up menu.
A bit old question and you may already figured out how to fix it, but here's a solution for people struggling (like I was) with the same issue. In fact, the documentation says the following:
Note: In some cases, the Android system will show your action bar tabs as a drop-down list in order to ensure the best fit in the action bar.
To avoid the drop-down list when your tab items don't fit the screen, add your tabs to ActionBar and set navigation mode after adding the items.
ActionBar bar = getSupportActionBar();
//bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Don't set navigation mode yet, if you do then portrait mode will revert to list mode if tab items don't fit the screen
bar.setLogo(logo);
bar.setHomeButtonEnabled(false);
bar.setDisplayHomeAsUpEnabled(true);
bar.setDisplayShowTitleEnabled(false);
// Add lots of tab items
for (int i = 0; i < channels.length; i++) {
ActionBar.Tab tab = bar.newTab();
String[] s = channels[i].split(":");
tab.setText(s[0]);
tab.setTag(s[1]);
tab.setTabListener(this);
bar.addTab(tab);
}
// Set navigation mode now, that will show all tabs in portrait mode instead of drop-down regardless the screen size
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
That's it :)
Related
I'm developing an application in which I'd like the tab bar to appear and disappear based on the direction the user is scrolling. I use bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); to show the tab bar and bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); to hide the tabbar. The only problem is that when I hide the tab, it leaves behind a blank gray space (see second figure) instead of having the listview fill up the space. I also tried overlaying the actionbar by using requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); but it didn't seem to help. I can provide any additional code needed. Any ideas? Thanks in advance!
Try removing all tabs and setting the navigation mode to standart:
actionBar.removeAllTabs();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
I have Actionbar Sherlock and SlidingMenu set up in my project. I want the menu to slide in under the actionbar, so I set:
setSlidingActionBarEnabled(false);
Though, when I have the action bar Navigation Mode set up with tabs:
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
They stick with the action bar instead of sliding away. That causes the issue of being able to switch tabs and the view pager switching while the menu stays open. Along with it not being the aesthetic I am going for.
Is it possible for the tabs to slide away from the action bar with the menu? Or would it just be more practical to set up a custom implementation with radio buttons?
It's not possible to have the tabs slide when you are using NAVIGATION_MODE_TABS.
The alternative is to use the ViewPagerIndicator library and the TabPageIndicator mode from that. That way the tabs are a part of the activity layout, and will slide. The downside is that the tabs won't get embedded in the action bar on larger devices or when a device is in landscape.
Because of my long app name (and other factors) the 4 tabs that I have are now collapsed. This happens on devices using large-layout. In portrait mode, it looks like the picture above. However, in landscape mode, there is plenty of room for the name and 4 tabs.
I already tried deleting the title but the tabs are still collapsed. How do I make it so that the tabs always show and if there is no room, have it hide the app name. I'd rather not have ellipses (App Name Go...). I'd rather just hide the title completely. I need this specifically for large-layout in portrait mode.
Any help would be appreciated.
To avoid this, fisrt add tabs after that set navigation mode. Like this,
ActionBar bar = getSupportActionBar();
//dont set navigation mode now.
bar.setLogo(logo);
bar.setHomeButtonEnabled(false);
bar.setDisplayHomeAsUpEnabled(true);
bar.setDisplayShowTitleEnabled(false);
// Now add tabs
ActionBar.Tab tab1 = bar.newTab();
ActionBar.Tab tab2 = bar.newTab();
ActionBar.Tab tab3 = bar.newTab();
tab1.setText("Packages");
tab1.setIcon(R.drawable.abs__ic_menu_share_holo_dark);
tab2.setText("Blogs");
tab2.setIcon(R.drawable.abs__ic_voice_search);
tab3.setText("Gallery");
tab3.setIcon(R.drawable.abs__ic_cab_done_holo_dark);
tab1.setTabListener(new MyTabListener());
tab2.setTabListener(new MyTabListener());
tab3.setTabListener(new MyTabListener());
bar.addTab(tab1);
bar.addTab(tab2);
bar.addTab(tab3);
// Now set navigation mode
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
You do not control when action bar tabs are collapsed. That is up to Android. I filed an issue about this that was rejected.
If you absolutely cannot have the collapsed UI, switch to a ViewPager and either PagerTabStrip, the tab indicator from ViewPagerIndicator, or any other ViewPager tab implementation.
Action Bar will collapse tabs by default when area available is less. In portrait view, it creates another tab panel below the Action Bar. You can force this behavior in landscape mode also:
try {
Class c = Class.forName("com.android.internal.app.ActionBarImpl");
Method m = c.getDeclaredMethod("setHasEmbeddedTabs",boolean.class);
m.setAccessible(true);
m.invoke(getActionBar(),false); //-- do not embed tabs --
}catch (Exception e) {
e.printStackTrace();
}
Note: This is a reflection hack, and underlying private class can change in future versions.
I have two fragments. One displays my general content (fragment A). The other, fragment B, is displayed over the top of fragment A. I would like for my action bar to have a z-order in the middle of these two layouts. That is, the fragment B would be displayed in front of the action bar.
My question is, is it possible to display a view in front of the action bar?
It is possible.
After all, applications can already display in full screen and not in full screen with the action bar whenever they like. You can set that programmatically yourself in Java.
import android.app.ActionBar;
...
// Show action bar
ActionBar actionBar = getActionBar();
actionBar.show();
...
// Hide action bar
ActionBar actionBar = getActionBar();
actionBar.hide();
Just make sure there is a good reason to alternate this common UI convention on Android.
I am using a action bar. I have menu items on that. I have set the property on it as
android:showAsAction="ifRoom|withText"
So it's working in Potrait and landscape really well. On one page I have Tabs, it's not recognizing tabs and overwriting the tabs. What I would like to do is, in Potarit just show tabs and all menu in drop down. In Landscape show tabs and as many menu items possible on action bar.
Thanks,
Have a res/menu/options.xml and a res/values-land/options.xml to distinguish the cases. Or, if the rule really is not portrait vs. landscape but a minimum screen width, use res/menu/options.xml and res/menu-wNNNdp/options.xml, where NNN is the minimum width in dp for when you want to use some other approach for your menu.