简体   繁体   English

如何在反应原生android中锁定景观方向?

[英]How to lock the orientation to Landscape in react native android?

I'm creating an Android app using react-native.我正在使用 react-native 创建一个 Android 应用程序。 I need to create the app for the Nexus 9 tab in Landscape mode.我需要在横向模式下为 Nexus 9 选项卡创建应用程序。 I already created the Nexus 9 tab emulator in Android studio with Android 10.0 x86 API level 29. The problem is, App is still locked to portrait mode.我已经在 Android Studio 中使用 Android 10.0 x86 API 级别 29 创建了 Nexus 9 选项卡模拟器。问题是,应用程序仍然锁定为纵向模式。

To make the view in Landscape mode, I added android:screenOrientation="landscape" to the <activity> in AndroidManifest.xml as follows为了使视图处于横向模式,我将android:screenOrientation="landscape"到 AndroidManifest.xml 中的<activity>中,如下所示

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.sipandroid">

    <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:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

</manifest>

Even after I modified to the above code, App is still locked to the portrait mode .即使我修改了上面的代码, App仍然锁定在纵向模式 How can I take this to the landscape mode?我怎样才能把它带到横向模式?

简单地在您创建的特定活动的主体中使用此标签 android:orientation="vertical <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:screenOrientation="fullSensor" />

I fixed it.我修好了它。 The problem was the Android version and the API level .问题是 Android 版本和 API 级别 I changed it from 10.0 API level 29 to 9.0 API level 28 and now it's working我将它从 10.0 API 级别 29 更改为 9.0 API 级别 28,现在它可以工作了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM