How to hide the title bar for an Activity in XML with existing custom theme

AndroidAndroid LayoutTitlebar

Android Problem Overview


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 from all of my activities.

Can I set a no title style item somewhere?

Android Solutions


Solution 1 - Android

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.

Solution 2 - Android

You can modify your AndroidManifest.xml:

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

or use android:theme="@android:style/Theme.Black.NoTitleBar" if you don't need a fullscreen Activity.

Note: If you've used a 'default' view before, you probably should also change the parent class from AppCompatActivity to Activity.

Solution 3 - Android

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.

To apply the style to a particular Activity, open AndroidManifest.xml and add the following attribute to the activity tag;

<activity
    android:theme="@style/generalnotitle">

Solution 4 - Android

I don't like the this.requestWindowFeature(Window.FEATURE_NO_TITLE); because the title bar appears briefly, then disappears.

I also don't like the android:theme="@android:style/Theme.NoTitleBar" because I lost all of the 3.0+ Holo changes that the users of the new devices have gotten used to. So I came across this solution.

In your res/values folder make a file called styles.xml (If it doesn't already exist). In that file place the following code:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="Theme.Default" parent="@android:style/Theme"></style>
    <style name="Theme.NoTitle" parent="@android:style/Theme.NoTitleBar"></style>
    <style name="Theme.FullScreen" parent="@android:style/Theme.NoTitleBar.Fullscreen"></style>
</resources>

Next create a res/values-v11 with another styles.xml file (Once again this may already exist). In that file place the following code:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="Theme.Default" parent="@android:style/Theme.Holo"></style>
    <style name="Theme.NoTitle" parent="@android:style/Theme.Holo.NoActionBar"></style>
    <style name="Theme.FullScreen" parent="@android:style/Theme.Holo.NoActionBar.Fullscreen"></style>
</resources>

And if you are targeting 4.0+, create a res/values-v14 folder with yet another styles.xml file (Yes it may already be there). In that file place the following code:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="Theme.Default" parent="@android:style/Theme.Holo.Light"></style>
    <style name="Theme.NoTitle" parent="@android:style/Theme.Holo.Light.NoActionBar"></style>
    <style name="Theme.FullScreen" parent="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"></style>
</resources>

Finally, with all of these files created, open your AndroidManifiest.xml file you can add the code:

android:theme="@style/Theme.NoTitle"

to the activity tag of the activity you want no title for or the application tag if you want it to apply to the entire application.

Now your users will get the themes associated with their device version with the screen layout you desire.

P.S. Changing the value to android:theme="@style/Theme.FullScreen" will have the same effect, but also remove Notification bar.

Solution 5 - Android

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

In the manifest.xml file:

  1. 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">
    
  2. Or for a particular activity:

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

Solution 6 - Android

the correct answer probably is to not extend ActionbarActivity rather extend just Activity


if you still use actionbar activity seems this is working:

@Override
protected void onCreate(Bundle savedInstanceState) {		  
	super.onCreate(savedInstanceState);
	getSupportActionBar().hide(); //<< this
	setContentView(R.layout.activity_main);
}

seems this works too:

styles.xml:

   <style name="AppBaseTheme" parent="Theme.AppCompat.Light" >
 		  <item name="android:windowNoTitle">true</item>   <!-- //this -->     
   </style>

i could do like as Scott Biggs wrote. this kind of works. except there is no theme then. i mean the settings menu's background is transparent:

just change

public class MainActivity extends ActionBarActivity {

to Activity or FragmentActivity

public class MainActivity extends Activity  {

however i could make it look good enough using material design and not remove the actionbar: https://gist.github.com/shimondoodkin/86e56b3351b704a05e53

  1. set icon of application
  2. set colors of action bar to match design.
  3. set icon to settings menu
  4. add more icons (buttons on top)

it is by example of material design compatibility actionbar styling.

Solution 7 - Android

what works for me:

1- in styles.xml:

 <style name="generalnotitle" parent="Theme.AppCompat.Light" >
          <item name="android:windowNoTitle">true</item>   <!-- //this -->     
   </style>

2- in MainActivity

@Override
protected void onCreate(Bundle savedInstanceState) {          
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide(); //<< this
    setContentView(R.layout.activity_main);
}

3. in manifest inherit the style:

    <activity android:name=".MainActivity" android:theme="@style/generalnotitle">

Solution 8 - Android

If you use this.requestWindowFeature(Window.FEATURE_NO_TITLE) user will still be able to see the title bar just for a moment during launch animation when activity starts through onCreate. If you use @android:style/Theme.Black.NoTitleBar as shown below then title bar won't be shown during launch animation.

<activity 
    android:name=".MainActivity" 
    android:label="My App"
    android:theme="@android:style/Theme.Black.NoTitleBar"
    android:screenOrientation="portrait">

above example will obviously override your existing application theme, if you have existing theme then add <item name="android:windowNoTitle">true</item> to it.

Solution 9 - Android

when i tried to use all those high upvoted answers my app always crashed. (i think it has something to do with the "@android:style"?)

The best solution for me was to use the following:

android:theme="@style/Theme.AppCompat.NoActionBar"

No header / title bar anymore. Just place it in the <application>...</application> or <activity>...</activity> depending if you (don't) want it in the whole app or just a specific activity.

Solution 10 - Android

Create a theme as below.

 <!-- Variation on the Light theme that turns off the title -->
<style name="MyTheme" parent="android:style/Theme.Black">
    <item name="android:windowNoTitle">true</item>
</style>

Solution 11 - Android

Just use getActionBar().hide(); in your main activity onCreate() method.

Solution 12 - Android

Add

<item name="android:windowNoTitle">true</item>

inside AppTheme (styles.xml)

Solution 13 - Android

For AppCompat, following solution worked for me:

Add new theme style with no action bar in your styles.xml and set parent="Theme.AppCompat.NoActionBar".

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">

    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimary</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowBackground">@color/colorPrimary</item>

</style>


Now implement the same theme style to your splash screen activity in androidManifest.xml

<activity
        android:name=".ActivityName"
        android:theme="@style/SplashTheme"> // apply splash them here 
        
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>

Here is result:

enter image description here

Solution 14 - Android

You just need to change AppTheme style in Style.xml if you replace the definition from DarkActionBar

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

to NoActionBar

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

the AppTheme defined in AndroidManifast.xml

Solution 15 - Android

In your onCreate method, use the following snippet:

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);

Solution 16 - Android

You can use this code in your java file

add this line before you set or load your view

requestWindowFeature(Window.FEATURE_NO_TITLE); 
setContentView(R.layout.activity_main);

Solution 17 - Android

Add both of those for the theme you use:

	<item name="windowActionBar">false</item>
	<item name="android:windowNoTitle">true</item>

Solution 18 - Android

I believe there is just one line answer for this in 2020

Add the following line to the styles.xml

<item name="windowNoTitle">true</item>

Solution 19 - Android

Add this style to your style.xml file

 <style name="AppTheme.NoActionBar">
     <item name="windowActionBar">false</item>
     <item name="windowNoTitle">true</item>
 </style>

After that reference this style name into your androidManifest.xml in perticular activity in which you don't want to see titlebar, as like below.

<activity android:name=".youractivityname"
     android:theme="@style/AppTheme.NoActionBar">
</activity>

Solution 20 - Android

I'm using a support widget Toolbar v7. So, in order to be able to delete or hide the Title we need to write this.

Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);

//RemoveĀ”ing title bar
getSupportActionBar().setDisplayShowTitleEnabled(false);

Solution 21 - Android

To Hide both Title and Action bar I did this:

In activity tag of Manifest:

android:theme="@style/AppTheme.NoActionBar"

In Activity.java before setContentView:

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

i.e.,

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

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

NOTE: You need to keep these lines before setContentView

Solution 22 - Android

Or if you want to hide/show the title bar at any point:

private void toggleFullscreen(boolean fullscreen)
{
	WindowManager.LayoutParams attrs = getWindow().getAttributes();
	if (fullscreen)
	{
		attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
	}
	else
	{
		attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
	}
	getWindow().setAttributes(attrs);
}

Solution 23 - Android

I would like to prefer:-

  • AppTheme (Whole app theme)
  • AppTheme.NoActionBar (theme without action bar or toolbar)
  • AppTheme.NoActionBar.FullScreen (theme without action bar & without status bar)

Theme style like:-

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorDarkPrimary</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar" parent="AppTheme">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.NoActionBar.FullScreen" parent="AppTheme.NoActionBar">
    <item name="android:windowFullscreen">true</item>
</style>

Also put below code after super.onCreate(savedInstanceState) in onCreate menthod

super.onCreate(savedInstanceState)    
this.window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN)

Solution 24 - Android

In my case, if you are using android studio 2.1, and your compile SDK version is 6.0, then just go to your manifest.xml file, and change the following code:

Here is the code:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.lesterxu.testapp2">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.NoActionBar">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

And here is the snip shoot(see the highlight code): enter image description here

Solution 25 - Android

This Solved my problem

In manifest my activity:

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".SplashScreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

In style under "AppTheme" name:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme"
        parent="Theme.AppCompat.Light.NoActionBar">
        **<item name="windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>**
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

Solution 26 - Android

First answer is amphibole. here is my explain: add:

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
 

in oncreate() method.

before:

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);

(not just before setContentView) if don't do this u will get forceclose. +1 this answer.

Solution 27 - Android

If you do what users YaW and Doug Paul say, then you have to have in mind that window features must be set prior to calling setContentView. If not, you will get an exception.

Solution 28 - Android

I found two reasons why this error might occur.

One. 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);

Two. You have the Back/Up button inside the TitleBar, meaning that the current activity is a hierarchical child of another activity, in which case you might want to comment out or remove this line of code from inside the onCreate method.

getActionBar().setDisplayHomeAsUpEnabled(true);

Solution 29 - Android

This is how the complete code looks like. Note the import of android.view.Window.

package com.hoshan.tarik.test;

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

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
    }
}

Solution 30 - Android

Add theme @style/Theme.AppCompat.Light.NoActionBar in your activity on AndroidManifest.xml like this

<activity
        android:name=".activities.MainActivity"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
    </activity>

Solution 31 - Android

add in manifiest file ,

  android:theme="@android:style/Theme.Translucent.NoTitleBar"

add following line into ur java file,

  this.requestWindowFeature(Window.FEATURE_NO_TITLE);

Solution 32 - Android

I am using Android Xamarin and this worked for me.

SupportActionBar.Hide();
SetContentView(Resource.Layout.activity_main);

Solution 33 - Android

Simply change the parent tag of your App theme to "Theme.AppCompat.Light.NoActionBar"

Solution 34 - Android

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 the tag declaration and put it in the desired activity tag.

Solution 35 - Android

There are mentions of it in this post but no one explicitly addresses it, so maybe this will save people some time. If you are like me and have multiple classes extending one root class which extends ActionBarActivity, it may not be immediately obvious that trying to set that activity to a NoTitleBar/NoActionBar will throw an error, specifically:

"You need to use a Theme.AppCompat theme (or descendant) with this activity"

You can fix this changing the extends to Activity.

Solution 36 - Android

I used the solution from @YaW to remove the title and notification from my Activity. But, the title and notification would appear when showing a dialog. So, to apply this to a dialog, subclass the dialog as shown below:

public class MyDialog extends android.app.Dialog{
    @Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
				
	    super.onCreate(savedInstanceState);

	    setContentView(R.layout.mydialog);
    }    
}

Solution 37 - Android

WindowManager.LayoutParams in Android Studio documentation says FLAG_FULLSCREEN is "Window flag: hide all screen decorations (such as the status bar) while this window is displayed." so this flag does not make my content fill the whole screen.

Solution 38 - Android

In my case, my activity was extending AppCompatActivity.

class MyActivity: AppCompatActivity(){
    ...
}

So, other answers didn't work. I had to do this:

class MyActivity: AppCompatActivity(){
    this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE)
}

And it works!

Just add "support" before requestWindowFeature(...), if your activity extends AppCompatActivity.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJanuszView Question on Stackoverflow
Solution 1 - AndroidYaWView Answer on Stackoverflow
Solution 2 - AndroidRedaxView Answer on Stackoverflow
Solution 3 - AndroidJanuszView Answer on Stackoverflow
Solution 4 - AndroidDevin StewartView Answer on Stackoverflow
Solution 5 - AndroidwhiteShadowView Answer on Stackoverflow
Solution 6 - AndroidShimon DoodkinView Answer on Stackoverflow
Solution 7 - AndroidFlowraView Answer on Stackoverflow
Solution 8 - Androidraj cView Answer on Stackoverflow
Solution 9 - AndroidTryToSolveItSimpleView Answer on Stackoverflow
Solution 10 - AndroidsandyView Answer on Stackoverflow
Solution 11 - AndroidAnas Al HamdanView Answer on Stackoverflow
Solution 12 - AndroidnijasView Answer on Stackoverflow
Solution 13 - AndroidKrunalView Answer on Stackoverflow
Solution 14 - AndroidDaniel LeviView Answer on Stackoverflow
Solution 15 - AndroidMaheshView Answer on Stackoverflow
Solution 16 - AndroidAneh ThakurView Answer on Stackoverflow
Solution 17 - Androidandroid developerView Answer on Stackoverflow
Solution 18 - AndroidCharlieView Answer on Stackoverflow
Solution 19 - AndroidNo oneView Answer on Stackoverflow
Solution 20 - AndroidMontDeskaView Answer on Stackoverflow
Solution 21 - AndroidShailendra MaddaView Answer on Stackoverflow
Solution 22 - AndroidcprcrackView Answer on Stackoverflow
Solution 23 - AndroidRahulView Answer on Stackoverflow
Solution 24 - AndroidLesterView Answer on Stackoverflow
Solution 25 - AndroidSamirView Answer on Stackoverflow
Solution 26 - AndroidDavidView Answer on Stackoverflow
Solution 27 - AndroidfergermView Answer on Stackoverflow
Solution 28 - AndroidDzhuneytView Answer on Stackoverflow
Solution 29 - AndroidTarikView Answer on Stackoverflow
Solution 30 - AndroidSamuel IvanView Answer on Stackoverflow
Solution 31 - AndroidKunal DharaiyaView Answer on Stackoverflow
Solution 32 - AndroidjaseView Answer on Stackoverflow
Solution 33 - AndroidCloyView Answer on Stackoverflow
Solution 34 - AndroidFred GrottView Answer on Stackoverflow
Solution 35 - AndroidfarnettView Answer on Stackoverflow
Solution 36 - AndroidChris SpragueView Answer on Stackoverflow
Solution 37 - AndroidLawnView Answer on Stackoverflow
Solution 38 - AndroidTeohan EksiView Answer on Stackoverflow