Holoeverywhere : how to programmatically remove at runtime the action bar from an activity
Asked Answered
L

2

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)

Linguistician answered 2/5, 2013 at 17:17 Comment(0)
T
24

See flag ThemeManager.NO_ACTION_BAR. Or just call

getSupportActionBar().hide();
Tanning answered 3/5, 2013 at 7:13 Comment(1)
It also works with setTheme(ThemeManager.DARK | ThemeManager.NO_ACTION_BAR) ; I was using ThemeManager.FULLSCREEN instead of NO_ACTION_BARLinguistician
R
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.

Rushton answered 2/5, 2013 at 17:46 Comment(5)
thanks for answer, but in your example you're not using the holoeverywhere library, but the "pure" android SDK...Linguistician
Oh sorry i oculdn't help you out. I replied with whatever i had knowledge of.Rushton
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 !Linguistician
Thanks for the answer... This prevented me from not supporting a few API versions :-)Galloromance
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.Isosteric

© 2022 - 2024 — McMap. All rights reserved.