9

Which is the correct way to remove the action bar inside an activity ?

My activity extends org.holoeverywhere.app.Activity

I've a custom Application class that extends org.holoeverywhere.app.Application and at startup execs this static code :

ThemeManager.setDefaultTheme(ThemeManager.DARK);
ThemeManager.map(ThemeManager.DARK, R.style.Holo_Demo_Theme);
ThemeManager.map(ThemeManager.LIGHT,  R.style.Holo_Demo_Theme_Light);
ThemeManager.map(ThemeManager.MIXED, R.style.Holo_Demo_Theme_Light_DarkActionBar);
ThemeManager.map(ThemeManager.DARK | ThemeManager.FULLSCREEN,  R.style.Holo_Demo_Theme_Fullscreen);
ThemeManager.map(ThemeManager.LIGHT | ThemeManager.FULLSCREEN, R.style.Holo_Demo_Theme_Light_Fullscreen);
ThemeManager.map(ThemeManager.MIXED | ThemeManager.FULLSCREEN, R.style.Holo_Demo_Theme_Light_DarkActionBar_Fullscreen);

in my activity :

protected void onCreate(Bundle savedInstanceState) {

    ThemeManager.removeTheme(this);
    setTheme(ThemeManager.DARK | ThemeManager.FULLSCREEN);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

if I add requestWindowFeature(Window.FEATURE_NO_TITLE) in the code, on an android 4.1.1 -table- the bar is removed while on an handset -android 2.3.3- the bar is not removed.

Before introducing holoeverywhere everything worked fine with just requestWindowFeature(Window.FEATURE_NO_TITLE).

Which is the correct way to remove at runtime the actionbar in holoeverywhere ? (I want to do it at runtime because the user has the option to set a DARK or LIGHT layout, with a DARK default)

Maxj
  • 139
  • 1
  • 3
  • 10

2 Answers2

24

See flag ThemeManager.NO_ACTION_BAR. Or just call

getSupportActionBar().hide();
Prototik
  • 935
  • 4
  • 7
  • It also works with setTheme(ThemeManager.DARK | ThemeManager.NO_ACTION_BAR) ; I was using ThemeManager.FULLSCREEN instead of NO_ACTION_BAR – Maxj May 03 '13 at 09:34
2

You can do it programatically:

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class ActivityName extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // remove title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
    }
}

Or you can do it via your AndroidManifest.xml file:

<activity android:name=".ActivityName"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
</activity>

I added some lines so that you can show it in fullscreen, as it seems that's what you want.

Chintan Soni
  • 24,761
  • 25
  • 106
  • 174
  • thanks for answer, but in your example you're not using the holoeverywhere library, but the "pure" android SDK... – Maxj May 02 '13 at 18:12
  • Oh sorry i oculdn't help you out. I replied with whatever i had knowledge of. – Chintan Soni May 02 '13 at 18:15
  • With pure SDK everything works. After I introduced the library I have this problem. I think it's a "stupid" problem, but the library has NO documentation at all ! – Maxj May 02 '13 at 18:18
  • Thanks for the answer... This prevented me from not supporting a few API versions :-) – m13r Aug 11 '14 at 21:40
  • When I do this, I am left with a blank white rectangle where the action bar would have been. What have I done wrong? Thanks. – AndyCr15 Aug 19 '17 at 09:05