If you have a requirement to design an Android Application that runs only in Landscape Mode (say you are designing a game) then you need to set orientation as LANDSCAPE for each activity class that you have.
How to do it ?In your activity class add setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) just before setContentView(R.layout.activity_main) in onCreate method.
package com.code2care.examples;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
public class LayoutExampleActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//This will make your app run only in Landscape mode!
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.activity_main);
}
}
Note : You have to add setRequestedOrientation() to each Activity class to force it work only in landscape.
More Posts related to Android,
- Change Android Toast background color
- Maven : java.lang.ClassNotFoundException: Xmx512m
- This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView) Lint Error
- Android Alert Dialog with Checkboxes example
- Android Error Generating Final Archive - Debug Certificate Expired
- How to add Newline to text in Android TextView
- Read Text file from SD Card : Android Programming
- [FIX] AndroidRuntime: FATAL EXCEPTION: main - java.lang.RuntimeException NullPointerException
- ActivityManager Warning: Activity not started, its current task has been brought to the front
- INSTALL_FAILED_INSUFFICIENT_STORAGE Android Error
- Android Developers Bluetooth Tutorial
- java.lang.ClassNotFoundException android.support.v7.widget.Toolbar [Fix]
- Android: Save Data in local Db using Android Room
- Channel 50 SMSes received every few minutes Android Phones
- 21 Useful Android Emulator Short-cut Keyboard Keys
- Changing Android Intent Tittle using java code
- Android : No Launcher activity found! Error
- How to change TextView or EditText Text Color on Focus and on Press
- How to display Toast on Button Click : Android
- Android : Execute some code after back button is pressed
- Stop android adb service from command prompt or terminal
- [Soluiton] You already have the latest version of Android Studio installed
- Create Custom Android AlertDialog
- Android R Cannot Be Resolved To A Variable
- How to make Android EditText not editable
More Posts:
- What is CA FE BA BE 00 00 00 3D in Java Class Bytecode - Java
- Common Microsoft Teams sign in errors and how to fix - Teams
- Portable Notepad++ for windows - NotepadPlusPlus
- Twitch chat down, error loading data, content unavailable, streaming problem - News
- How to check if a port is in use using terminal [Linux or macOS] - MacOS
- How to enable Do Not Disturb mode for Notification Center in Mac OS X 10.10 Yosemite - Mac-OS-X
- Using Java 8 Month Enum with Examples - Java
- Change Android Toast background color - Android