How is application orientation (landscape or portrait) locked?

前端 未结 4 1115
春和景丽
春和景丽 2020-12-09 05:18

I have tried to freeze orientation using:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Although the display stays in

4条回答
  •  情书的邮戳
    2020-12-09 05:55

    Try this:

    1.- Set the desired screen orientation in your AndroidManifest.xml

    android:screenOrientation="portrait|landscape"
    

    It should look like this:

        
        
    

    2.- Add this to your onCreate void(or wherever you want) in your java Activity File(Example: "MainActivity.java"):

    super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
    

    It should look like this:

    protected void onCreate(Bundle savedInstanceState) {
        super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);}
    

    Now the screen wont move even if the Screen Rotation is on in the Device.

提交回复
热议问题