Making an Android app run full screen and landscape
Asked Answered
M

4

17

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?

Mizzle answered 6/1, 2013 at 12:58 Comment(4)
sorry, but it is to common question, just use google and android developer site: developer.android.com/develop/index.html; google.comBenn
Two quick Google searches revealed the answers to your questions. Force fullscreen on an activity: androidsnippets.com/how-to-make-an-activity-fullscreen Force orientation on an activity: #2150787Andaman
I have Googled it but in vain. In the Android Developers website, I couldn't figure it out despite going through all the properties etc.Mizzle
Yet another example of how pathetic "SO fundamentalism" can be. You could say "Use Google" to a massive number of SO questions, many of them with tens or hundreds of votes. Nobody seems to complain about them.Sunshine
J
21

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.

Jemima answered 6/1, 2013 at 13:38 Comment(1)
If set min sdk = 8, and use sensorLandscape in manifest, does application crash?Ripon
E
9
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

Effusion answered 6/1, 2013 at 13:2 Comment(1)
Its Much better...to add this into your respective activitiesSaddlecloth
M
4

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.

Mizzle answered 7/1, 2013 at 7:9 Comment(0)
E
1

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 ). !!!

Energetic answered 20/8, 2014 at 13:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.