Removing Title Bar From Activity

This example explains how you can remove title bar from your activity.

Algorithm:

1.) Create a new project by File-> New -> Android Project name it RemoveTitleBar.

2.) Write following into main.xml:

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".RemoveTitleBarActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

</RelativeLayout>

 

 

3.) Run for output.

Steps:

1.) Create a project named RemoveTitleBar and set the information as stated in the image.

Build Target: Android 4.4
Application Name: RemoveTitleBar
Package Name: com.example.RemoveTitleBar
Activity Name: RemoveTitleBarActivity

titlebar1

2.) Open RemoveTitleBarActivity.java file and write following code there:

 

package com.example.removetitlebar;

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

public class RemoveTitleBarActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.remove_title_bar, menu);
return true;
}
}

 

3.) Compile and build the project.

Output

titlebar2

titlebar3