Sunday, 19 August 2012

Full Screen Activity And Orientation Lock - Android

In android locking screen orientation is just one line stuff.
In the same way if you want to make your activity full screen then it is easy. Making activity full screen means we are hiding status bar.
Here is code for both stuffs,

Main.java

package com.android.fullscreenactivity;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class Main extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        //Here you can make activity fullscreen.
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        
        //Here you can lock orientation.
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
       
        setContentView(R.layout.main);
    }
}

There is no need of setting any permissions in manifest for this.

No comments:

Post a Comment