ActionBarSherlock with Tabs - android

I am trying to implement ActionBarSherlock with three tabs in the way that the tabs are placed in the same line as HomeButton. See the picture below:
I created the ActionBarSherlock and added the three tabs but they did not appear on the screen. What did I miss?
Here is my code:
//ActionBarSherlock settings
ActionBar actionBar=getSupportActionBar();
Resources res=getResources();
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setLogo(res.getDrawable(R.drawable.logo));
actionBar.setSplitBackgroundDrawable(res.getDrawable(R.drawable.separator));
actionBar.setBackgroundDrawable(res.getDrawable(R.drawable.navbar));
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
//Tabs
actionBar.addTab(actionBar.newTab().setText("apps").setIcon(R.drawable.ico_apps_normal).setTabListener(this).setTag("apps tab"),true);
actionBar.addTab(actionBar.newTab().setIcon(R.drawable.ico_add_normal).setTabListener(this).setTag("add tab"));
actionBar.addTab(actionBar.newTab().setIcon(R.drawable.ico_news_normal).setTabListener(this).setTag("news tab"));

Try adding
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
before you start adding your tabs. It seems like you haven't set your navigation mode.
I've also answered a similar question regarding Actionbars and navigaton tabs here

Related

How to hide ActionBar, but keep the Tab navigation buttons?

I'm new in creating Android apps, and I would like to hide the Title, App Icon, and the whole top area of the ActionBar, but keep the Tabs Navigations below it. Is it possible?
Here is an explanation picture about what I want exactly:
This will show only tabs:
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
// Set your tabs below

Removing an icon from the Actionbar

I want a custom ActionBar with Tabs that has a graphic background (displaying just one image) and 3 tabs.
I can't remove the icon of the actionbar.I've been through tens of stackoverflow questions about how to remove the icon and title, but nothing worked.
I have a minSdk=14, ViewPager, ActionBar compat7, ActionBarActivity. Would any of these hinder it?
This is the code I have. Some declarations are excessive, I've been trying everything I could.
The best I got is an actionbar with no title, but the icon never goes away.
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayShowHomeEnabled(false); // this hides the icon well but doesn't
// work if you use actionbar tabs (viewpager)
solution below
Thanks
Have you tried for actionBar.setDisplayShowHomeEnabled(false)
The solution is this:
((View)findViewById(android.R.id.home).getParent()).setVisibility(View.GONE);
as seen on: https://github.com/JakeWharton/ActionBarSherlock/issues/327#issuecomment-10593286
Using actionBar.setDisplayShowHomeEnabled(false) hides the icon, but your actionbar ends up being below the viewpager tabs (if you're using any)

Tabs go to top if i set customView of ActionBar on Android

I add tabs and viewpager to my project.
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Everything is perfect until i set custom view of actionBar:
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
....
actionBar.setCustomView(vv,layoutParams);
Perfect: ActionBar itself at the top and tabs are below the actionBar.
When i set the custom view, tabs change place and goes to top and actionBar goes to below of tabs.
What am i doing wrong? I want the actionbar stay always at the top of the screen.
You can vote for this bug on Android code:
https://code.google.com/p/android/issues/detail?id=36191
There are some tricks to avoid this that you can read here: https://github.com/JakeWharton/ActionBarSherlock/issues/327
But the official Google answer is
This is a working as intended UX decision.
(Roman Nurik).

Actionbar Sherlock tabs and navigation list

I'm using sherlockbar. How do I add a ActionBar bar with tabs and a navigation list? As this image from Google Maps
In my code, I can not seem to set two behaviors for ActionBar
ActionBar bar = getSherlockActivity().getSupportActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
the opt navigation (Meus Lugares) are added using the menu onCreateMenu .
The other are Tabs which you add using
bar.AddTab()

Android - How to get rid of the bar above the ActionBar

EDIT: Android-Developers answer below explains solution very well
My problem is there are another bar, not exactly sure what it's name is - TitleBar? (The bar with the menu button and the white square logo) Above my ActionBar. What I ideally want is to merge my ActionBar with that bar or if not possible, implement my own bar completely amongst the tabs with icon and menu button. I have tried several things (see below image) and the rough code of how I am add the tabs is shown below as well.
Adding tabs to the ActionBar code:
actionBar = getActionBar(); // Get reference to ActionBar
// Add some navigation tabs...
// 1. Enable ActionBar navigation tabs
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(false);
// 2. Add the tabs
Tab programTab = actionBar.newTab();
Tab settingsTab = actionBar.newTab();
Tab historyTab = actionBar.newTab();
programTab.setText("Program")
.setTabListener(new TabListener<Fragment_Program>(
this, "Program", Fragment_Program.class));
settingsTab.setText("Settings")
.setTabListener(new TabListener<Fragment_Settings>(
this, "Settings", Fragment_Settings.class));
historyTab.setText("History")
.setTabListener(new TabListener<Fragment_History>(
this, "History", Fragment_History.class));
actionBar.addTab(programTab);
actionBar.addTab(settingsTab);
actionBar.addTab(historyTab);
I was under the impression getActionBar() got reference to the existing bar which sits above my ActionBar in the screenshot.. that would be ideal.
Current application theme is android:theme="#android:style/Theme.Holo.Light.DarkActionBar"
Anyway, I have tried the following:
Various manifest changes including various .NoTitleBar combinations
requestWindowFeature(Window.FEATURE_NO_TITLE); after super.onCreate() and before setContentView()
The reason I am using standard ActionBar is this for a hardware device that will be running at least 4.0 and the version is highly unlikely to change.
Any thoughts?
Cheers
As I can understand you want to remove that view right?
The problem is that it your ActionBar. I guess you want to use Tabs, but without the ActionBar like many of the apps which are doing that. To achieve this use :
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.setDisplayShowTitleEnabled(false);
bar.setDisplayShowHomeEnabled(false);
But don't forget something, if you want to achieve this, you should not inflate any menu in your Fragment / Activity :
#Override
public boolean onCreateOptionsMenu(Menu menu) {
//getSupportMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
You should see #ColorWP answer here
The Window flags are set already set inside super.onCreate(savedInstanceState); in which case you may want to use the following order of commands:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);

Categories

Resources