How to lock screen orientation to landscape
Add this in Manifest.xml file
<activity android:name=".MainActivity"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation|screenSize"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
How to Lock Android App's Orientation to Portrait in Phones and Landscape in Tablets?
You just have to define the property below inside the activity element in your AndroidManifest.xml
file. It will restrict your orientation to portrait.
android:screenOrientation="portrait"
Example:
<activity
android:name="com.example.demo_spinner.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
if you want this to apply to the whole app define the property below inside the application tag like so:
<application>
android:screenOrientation="sensorPortrait"
</application>
Additionaly, as per Eduard Luca's comment below, you can also use screenOrientation="sensorPortrait"
if you want to enable rotation by 180 degrees.
Flutter: How to set and lock screen orientation on-demand
First import the services package:
import 'package:flutter/services.dart';
This will give you access to the SystemChrome
class, which "Controls specific aspects of the operating system's graphical interface and how it interacts with the application."
When you load the Widget, do something like this:
@override
void initState(){
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
}
then when I leave the page, put it back to normal like this:
@override
dispose(){
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
super.dispose();
}
Related Topics
How to Get Current Activity's Layout and Views via Adb
Android 2.1 Programmatically Unmount Sdcard
Design Android Edittext to Show Error Message as Described by Google
Android Mediaplayer Error (1, -2147483648)
Create Custom Notification, Android
Pop Up Window Over Android Native Incoming Call Screen Like True Caller Android App
Remove Underline from Links in Textview - Android
Android App Specific Soft Keyboard
Android Layout Replacing a View with Another View on Run Time
Update Fragment from Viewpager
Schedule a Work on a Specific Time with Workmanager
Android Push Notification (Gcm), Is There Any Daily Limit
Better Way to Format Currency Input Edittext