HideTitleBar in Android

Introduction

 
This article explains how to hide the Title Bar on Android. Android Studio is used to create the sample.
 
TitleBar
 
The Title Bar contains the title of your application that you can set depending on your requirements. You can also hide the Title Bar using the Android manifest.xml file and also through coding.
 
Hide Title Bar using Java code
 
First, we will see how to hide the Title Bar using Java code. To do that you need to call the requestWindowFeature(Window.FEATURE_NO_TITLE)  method of an Activity. But you need to call this before the setContentView( ) method of an Activity.
  1. @Override   
  2. protected void onCreate(Bundle savedInstanceState)  
  3. {   
  4.         super.onCreate(savedInstanceState);   
  5.         requestWindowFeature(Window.FEATURE_NO_TITLE);   
  6.         setContentView(R.layout.activity_main);   
  7.    
  8.     }   
  9. }   
Hide Title Bar using Android Manifest.xml file
 
To hide the Title Bar using the Android Manifest.xml file you need to set the Android theme to NoTitleBar like this:
  1. android:theme="@android:style/Theme.NoTitleBar"> 
Android Manifest.xml file
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     package="com.hidetitlebar"  
  4.     android:versionCode="1"  
  5.     android:versionName="1.0" >  
  6.    
  7.     <uses-sdk  
  8.         android:minSdkVersion="7"  
  9.         android:targetSdkVersion="16" />  
  10.    
  11.     <application  
  12.         android:allowBackup="true"  
  13.         android:icon="@drawable/ic_launcher"  
  14.         android:label="@string/app_name"  
  15.         android:theme="@style/AppTheme" >  
  16.         <activity  
  17.             android:name="com.hidetitlebar.MainActivity"  
  18.             android:label="@string/app_name"  
  19.             android:theme="@android:style/Theme.NoTitleBar">  
  20.    
  21.             <intent-filter>  
  22.                 <action android:name="android.intent.action.MAIN" />  
  23.    
  24.                 <category android:name="android.intent.category.LAUNCHER" />  
  25.             </intent-filter>  
  26.         </activity>  
  27.     </application>  
  28.    
  29. </manifest> 
Step 1
 
Create a project like this:
 
hidetitlebarproject
 
Step 2
 
Create an XML file with the following:
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:paddingBottom="@dimen/activity_vertical_margin"  
  6.     android:paddingLeft="@dimen/activity_horizontal_margin"  
  7.     android:paddingRight="@dimen/activity_horizontal_margin"  
  8.     android:paddingTop="@dimen/activity_vertical_margin"  
  9.     tools:context=".MainActivity"  
  10.     android:background="#d155">  
  11.    
  12.     <TextView  
  13.         android:layout_width="wrap_content"  
  14.         android:layout_height="wrap_content"  
  15.         android:text="Hide Title Bar"  
  16.         android:textSize="40dp"  
  17.         android:layout_centerInParent="true"/>  
  18.    
  19. </RelativeLayout> 
Step 3
 
Create a Java class file with the following.
 
In this, you will hide the Title Bar by calling the requestWindowFeature(Window.FEATURE_NO_TITLE)  method of an Activity. But you need to call this before the setContentView( ) method of an Activity.
  1. package com.hidetitlebar;  
  2. import android.os.Bundle;  
  3. import android.app.Activity;  
  4. import android.view.Menu;  
  5. import android.view.Window;  
  6. import android.view.WindowManager;  
  7.    
  8. public class MainActivity extends Activity {  
  9.     @Override  
  10.     protected void onCreate(Bundle savedInstanceState) {  
  11.         super.onCreate(savedInstanceState);  
  12.         requestWindowFeature(Window.FEATURE_NO_TITLE);  
  13.        
  14.       //     WindowManager.LayoutParams.FLAG_FULLSCREEN);//int flag, int mask  
  15.        
  16.         setContentView(R.layout.activity_main);  
  17.     }  
Step 4
 
Android Manifest.xml file
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     package="com.hidetitlebar"  
  4.     android:versionCode="1"  
  5.     android:versionName="1.0" >  
  6.     <uses-sdk  
  7.         android:minSdkVersion="7"  
  8.         android:targetSdkVersion="16" />  
  9.    
  10.     <application  
  11.         android:allowBackup="true"  
  12.         android:icon="@drawable/ic_launcher"  
  13.         android:label="@string/app_name"  
  14.         android:theme="@style/AppTheme" >  
  15.         <activity  
  16.             android:name="com.hidetitlebar.MainActivity"  
  17.             android:label="@string/app_name"  
  18.            >  
  19.             <intent-filter>  
  20.                 <action android:name="android.intent.action.MAIN" />  
  21.                 <category android:name="android.intent.category.LAUNCHER" />  
  22.             </intent-filter>  
  23.         </activity>  
  24.     </application>  
  25. </manifest> 
Step 5
 
hidetitlebar