ReactNative 屏幕锁定横屏
参阅官方说明: https://reactnative.dev/docs/improvingux#screen-orientation-lock
Android
在项目的 android/app/src/main/AndroidMainfest.xml
的 activity
标签中添加属性,注意:是添加到 activity
标签中
锁定横屏
android:screenOrientation="landscape"
锁定竖屏
android:screenOrientation="portrait"
添加后是这样的
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.demoapk">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:screenOrientation="landscape"
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
效果
强制横屏后的效果: