Home > DeveloperSection > Forums > hide the title bar for an Activity in XML with existing custom theme
Chintoo Semi

Total Post:135

Points:947
Posted on    June-04-2015 7:07 AM

 Android Android  Android Styles 
Ratings:


 1 Reply(s)
 469  View(s)
Rate this:

I want to hide the titlebar 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?



Mayank Tripathi
Mayank Tripathi

Total Post:397

Points:3117
Posted on    June-04-2015 7:32 AM

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);
//set content view AFTER ABOVE sequence (to avoid crash)
this.setContentView(R.layout.your_layout_name_here); 

this refers to the Activity.

Also,
you can 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 you can set this style to every Activity in which you 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.

And,
You can modify your AndroidManifest.xml:

<activity android:name=".MainActivity"
          android:label="@string/app_name"
          android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
You can use this for each activity in your project

The title bar can be removed in two ways as mentioned on the developer Android page:

In the manifest.xml file:

Add the following in application if you want to remove it for all the activities in an app:

<application android:theme="@android:style/Theme.Black.NoTitleBar">
Or for a particular activity:

<activity android:theme="@android:style/Theme.Black.NoTitleBar">

Don't want to miss updates? Please click the below button!

Follow MindStick