Cdacians

Cdacians
Cdacians

Friday 14 September 2012

How to hide title bar and status bar in Android application



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.

Either you can proceed with the below listings, or download code.
New Visitor? Like what you read? Then do subscribe to our blog
Subscribe
  • 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
We can achieve full screen view in either of the two ways:
  1. Include full screen theme in AndroidManifest XML
  2. Include Window settings in onCreate method of Activity class
Include full screen theme in AndroidManifest  XML:
1
2
3
<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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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:

Thanks
akm
www.cdacians.com

No comments:

Post a Comment