How to hide title bar and status bar in Android application
This post is going to be very short one and here we will discuss about how to hide title bar and status bar in Android application.
If you look at Gaming applications like ‘Cut the rope’, ‘Angry birds’ and more in your android device, applications are displayed in full screen view which covers entire area of the display to provide more user experience.
We will develop a sample application which has no title bar and no status bar.
Quick Links
Project Structure
- Create new android project [File >> New >> Android Project] with project name FullScreenExample
- Click next and select target android device version [I chose version 2.2]
- Click next and enter package name – ‘com.prgguru.android’
- Click finish
Code Listings
We can achieve full screen view in either of the two ways:
- Include full screen theme in AndroidManifest XML
- Include Window settings in onCreate method of Activity class
Include full screen theme in AndroidManifest XML:
<activity android:name=".YourClassName" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> </activity>
Just change YourClassName to the Activity class name ( in our application it is ‘FullScreenExampleActivity’).
Include Window settings in onCreate method of Activity class:
package com.prgguru.android; import android.os.Bundle; import android.app.Activity; import android.view.Window; import android.view.WindowManager; public class FullScreenExampleActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //No title bar is set for the activity requestWindowFeature(Window.FEATURE_NO_TITLE); //Full screen is set for the Window getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.main); } }
Demo
Congratulations, We are done.
Let us test the application:
Right click on the project >> Run as >> Android application >> Choose emulator or device
You could see this screen:
Download Source Code
Entire project is zipped and is available for download. Unzip the downloaded project and to import the project into eclipse, launch eclipse >> File >> Import.. >> Choose downloaded project(How to import android project in eclipse). If you just want to run the application in your mobile and see the output but don’t want to hit your head with source code, download application(apk) file and install it in your mobile device.
Download Source Code Download Application(apk)*apk in Android is the installation file simliar to exe in windows.
[pglinkadssmall]
I hope you enjoyed the post!! 🙂
Suggested posts for further reading
[pgfeedback]
[pgwriteforus]