[英]How to disable screen rotation (react-native)?
Is any chance to disable screen rotation (allow only vertical)? 是否有机会禁用屏幕旋转(仅允许垂直)? I would like to support only portrait view.
我只想支持纵向视图。 And need it to work on android and ios.
并且需要它在android和ios上工作。
Add screenOrientation in your Manifest.xml class 在Manifest.xml类中添加screenOrientation
<activity android:name=".YourActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" />
Put the below code in manifest file 将以下代码放在清单文件中
<activity android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden"> </activity>
In android :- 在android: -
using xml :- android:screenOrientation="portrait"
使用xml: -
android:screenOrientation="portrait"
using java :- 使用java: -
@Override
public void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
Write the below code in manifest file 在清单文件中写下以下代码
<activity
android:screenOrientation="portrait"
android:configChanges="orientation|screenSize">
</activity>
Winner: chuck this in the app code, I usually drop it right after all my imports. 获胜者:在应用程序代码中删除它,我通常在我的所有导入后立即删除它。
Expo.ScreenOrientation.allow(Expo.ScreenOrientation.Orientation.PORTRAIT); Expo.ScreenOrientation.allow(Expo.ScreenOrientation.Orientation.PORTRAIT);
Have a look at Android's official documentation 看看Android的官方文档
You just have to add this to your activity tag in your android MANIFEST
file : 您只需将其添加到android
MANIFEST
文件中的activity标记:
<activity
android:screenOrientation=["unspecified" | "behind" |
"landscape" | "portrait" |
"reverseLandscape" | "reversePortrait" |
"sensorLandscape" | "sensorPortrait" |
"userLandscape" | "userPortrait" |
"sensor" | "fullSensor" | "nosensor" |
"user" | "fullUser" | "locked"]
using the orientation that you want. 使用您想要的方向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.