Android开发之强制横屏和强制竖屏

xiaoxiao2021-02-28  132

强制竖屏设置

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">
转载请注明原文地址: https://www.6miu.com/read-19371.html

最新回复(0)