Sunit Prasad
Sunit Prasad

Reputation: 323

Making an Android app run full screen and landscape

I have seen certain apps, especially most of the games (Eg. Angry Birds, Temple Run etc) run fullscreen and in landscape mode when launched. Their orientation never changes and they never exit fullscreen when the screen is touched. How its done? What properties do I need to change or code?

Upvotes: 17

Views: 72892

Answers (4)

Tom Leese
Tom Leese

Reputation: 19719

If you prefer to use XML, you can change the AndroidManifest.xml:

<activity android:name="..."
    android:screenOrientation="landscape"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

</activity>

If you are targetting Android SDK 9 or above, you can use sensorLandscape instead of landscape which will mean that the screen will look the correct way up on both normal landscape orientation and reverse landscape orientation.

Upvotes: 21

rares
rares

Reputation: 61

Put this in onCreate() in every activity class (screens):

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);

This code will disable android notification bar ( pull up to down ). !!!

Upvotes: 1

Sunit Prasad
Sunit Prasad

Reputation: 323

The problem is solved, and based on the answers given above, what I did was,

Step 1 : In the manifest.xml file,

<application
. . .
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
. . .
</application>

Step 2 : In the Java file, I made the following changes,

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
   }

and now my app runs fullscreen, landscape without any issues. Thank You all.

Upvotes: 4

siranen
siranen

Reputation: 374

import android.view.Window;
import android.view.WindowManager;
import android.content.pm.ActivityInfo;

@Override public void onCreate(Bundle savedInstanceState)
{
    ...

    // Set window fullscreen and remove title bar, and force landscape orientation
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    ...
}

Solution to your problem

Upvotes: 9

Related Questions