Turn off screen display on Android

When I press the button, I want to turn off the screen rotation in all my actions . How can i do this?

BTW, the phone can be located in landscape or portrait position when the user presses a button.

+2
source share
3 answers

I found a solution:

in manifest.xml:

 <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" android:name="MyApplication">

in MyApplication.java:

public class UPackingListApplication extends Application {

    public void onConfigurationChanged(Configuration newConfig) {
        newConfig.orientation = [orientation we wanna to use (according to ActivityInfo class)];
        super.onConfigurationChanged(newConfig);
    }


}
+3
source

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

+12
source

AndroidManifest.xml

<activity android:name="MainActivity" android:configChanges="orientation">

, ( ).

Android?

+4
source

Source: https://habr.com/ru/post/1782731/


All Articles