3

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.

Showing the unwanted standard bar above the ActionBar

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

mgibson
  • 6,103
  • 4
  • 34
  • 49
  • the other is the one with the hours? – Blackbelt Apr 10 '13 at 08:29
  • No that is the NotificationBar, The one in between where the Menu button and Logo are – mgibson Apr 10 '13 at 08:31
  • If you want, you can add your tab on your action bar. See [this post](http://stackoverflow.com/questions/9895958/android-actionbar-tabs-set-initially-selected-tab) and [this link](http://developer.android.com/reference/android/app/ActionBar.html#addTab%28android.app.ActionBar.Tab%29). Doing so, you can "merge" 2 bar in only one. – JJ86 Apr 10 '13 at 08:31
  • That is the code I was using the addTab() method from ActionBar, that's why I am confused :) I added the code btw – mgibson Apr 10 '13 at 08:36

2 Answers2

4

As I can understand you want to remove that view right?

enter image description here

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;
}
hardartcore
  • 16,886
  • 12
  • 75
  • 101
  • Yes, that is exactly what I am trying to do! Hmm, that gets rid of the logo and switches the bars around leaving the ActionBar on top with that bar still with the menu button minus the logo – mgibson Apr 10 '13 at 08:39
  • I have a reference to ActionBar at the moment, I can hide that no problem and when I do both my tabs and the above bar with the menu and logo dissappear. It seems like the above bar that I do not want is in fact part of the ActionBar – mgibson Apr 10 '13 at 08:46
  • ActionBar is the black layout with the white icon and overflow icon. If you want to hide it and show only the tabs, just check the edited answer. – hardartcore Apr 10 '13 at 08:48
  • Ah perfect! Cheers, commenting that out did the job! Now I'll just create my own menu icon :) Thanks – mgibson Apr 10 '13 at 08:52
2

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);
Community
  • 1
  • 1
Mohsen Afshin
  • 13,273
  • 10
  • 65
  • 90
  • `requestWindowFeature(Window.FEATURE_NO_TITLE);` results in a `NullPointerException` and `getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);` gets rid of the `NotificationBar` at the top which I do not want to do – mgibson Apr 10 '13 at 08:43
  • I just mentioned the correct order of the commands and I've tested 'FEATURE_NO_TITLE' already and it worked, I guess that 'NullPointerException' is from some other codes .. – Mohsen Afshin Apr 10 '13 at 08:49
  • I agree, am fairly new to Fragment so I am sure there is some faults lying around :P thanks anyway – mgibson Apr 10 '13 at 08:53