Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top