How do I disable orientation change on Android?

后端 未结 12 1005
一向
一向 2020-11-22 02:45

I have an application that I just would like to use in portrait mode, so I have defined android:screenOrientation=\"portrait\" in the manifest XML. This works OK for the HTC

12条回答
  •  后悔当初
    2020-11-22 02:57

    In OnCreate method of your activity use this code:

        @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    

    Now your orientation will be set to portrait and will never change.

提交回复
热议问题