Disable screen rotating on Android [duplicate]

半世苍凉 提交于 2019-12-01 10:36:00

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

mdma

You can change your AndroidManifest.xml to

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

Which informs the OS that you will handle these config changes (by doing nothing.)

See How do I disable orientation change on Android?

I've found the 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);
    }


}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!