How to control landscape and portrait programmatically in android?

前端 未结 5 1138
慢半拍i
慢半拍i 2021-02-06 07:07

I developed on application using android sdk 4.0 and I install that .apk file in my samsung tab. When I run that application it is working properly. If I change the tab portra

5条回答
  •  我寻月下人不归
    2021-02-06 07:12

    add android:screenOrientation="portrait" for each activity in your manifest.xml file.

    You can do this programmatically too, for all your activities making an AbstractActivity that all your activities extends.:-

    public abstract class AbstractActivity extends Activity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    }
    

提交回复
热议问题