How can I disable landscape mode for some of the views in my Android app?
Add this android:screenOrientation="portrait"
in your manifest file where you declare your activity like this
<activity android:name=".yourActivity"
....
android:screenOrientation="portrait" />
If you want to do using java code try
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
before you call setContentView
method for your activity in onCreate()
.
Hope this help and easily understandable for all...
Add android:screenOrientation="portrait"
to the activity you want to disable landscape mode.
If you want user-settings,
then I'd recommend setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
You can change the settings from a settings menu.
I require this because my timers must correspond to what's on the screen, and rotating the screen will destroy the current activity.
If you are using Xamarin C# some of these solutions will not work. Here is the solution I found to work.
[Activity(MainLauncher = true, Icon = "@drawable/icon", ScreenOrientation = ScreenOrientation.Portrait)]
Above the class works well, similar to the other solutions, also not globally applicable and needs to be placed in each activity header.
In the <apphome>/platform/android
directory created AndroidManifest.xml
(copying it from the generated one).
Then add android:screenOrientation=
"portrait
" to ALL of the activity elements.
If you want to disable Landscape mode for your android app
( or a single activity) all you need to do is add,
android:screenOrientation="portrait"
to the activity tag in AndroidManifest.xml
file.
Like:
<activity android:name="YourActivityName"
android:icon="@drawable/ic_launcher"
android:label="Your App Name"
android:screenOrientation="portrait">
Another Way , Programmatic Approach.
If you want to do this programatically ie. using Java code. You can do so by adding the below code in the Java class of the activity that you don't want to be displayed in landscape mode.
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
I hope it helps you .For more details you can visit here enter link description here