views:

471

answers:

4

I want to hide the title bar for some of my activities. The problem is that I applied a style to all my activities, therefore I can't simply set the theme to @android:style/Theme.NoTitleBar.

Using the NoTitleBar theme as a parent for my style would remove the title bar for to much activities. Can I set a no title style item somewhere?

+3  A: 

Do this in your onCreate method.

//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);

//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

this refers to the Activity.

YaW
Great answer. You don't have to do both though, removing the notification bar may be overkill.
Jim Blackler
Thanks but that is not in XML...
Janusz
Be certain to put it *before* the call to setContentView(R.id.x), otherwise it will crash. The reason wasn't immediately obvious to me.08-13 12:47:33.561 E/AndroidRuntime( 9125): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.SplashActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
mobibob
A: 

ahem you can apply themes to individual activities in xml such as no title. In other words take it out of your application tag open tag declaration and put it in the desired activity tag

Fred Grott
That means I have to apply the theme to all my activities but the one that has no title and then recreate my theme without a titlebar and set it to the activity with the missing title?
Janusz
+2  A: 

I now did the following.

I declared a style inheriting everything from my general style and then disabling the titleBar.

<style name="generalnotitle" parent="general">
    <item name="android:windowNoTitle">true</item>
</style>

Now I can set this style to every Activity in which I want to hide the title bar overwriting the application wide style and inheriting all the other style informations, therefor no duplication in the style code.

Janusz
+1  A: 

You can modify your AndroidManifest.xml:

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

Yuo can use this for each activity in your project.

Redax