时间:2021-02-02 10:11:25 | 栏目:Android代码 | 点击:次
强制竖屏设置
1.代码在Activity的onResume方法中添加如下代码
@Override protected void onResume() { /** * 设置为横屏 */ if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } super.onResume(); }
2.在配置文件中对Activity节点添加Android:screenOrientation属性(landscape是横向,portrait是纵向)
android:launchMode="singleTask" android:screenOrientation="portrait">
强制横屏设置
1.代码在Activity的onResume方法中添加如下代码
@Override protected void onResume() { /** * 设置为横屏 */ if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } super.onResume(); }
2.在配置文件中对Activity节点添加android:screenOrientation属性(landscape是横向,portrait是纵向)
android:launchMode="singleTask" android:screenOrientation="landscape">