android:screenOrientation="portrait" 在 Nexus 5x 运行 Marshmallow 上被忽略

android:screenOrientation="portrait" ignored on a Nexus 5x running Marshmallow

我收到报告称我的纵向应用程序可以在 Nexus 5X 运行 Marshmallow 上旋转为横向模式。我没有可以测试的,但为什么会这样?这是清单中我的 activity:

    <activity
            android:name=".app.MainActivity_"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.Activity"
            android:launchMode="singleTask"
            >
    </activity>

您必须将此用于 Activity!

<activity
   android:screenOrientation="portrait"
   android:configChanges="orientation|keyboardHidden">
</activity>

并且对于整个应用程序,您必须使用此代码,这将强制方向不是横向

<application 
  android:debuggable="true"
  android:icon="@drawable/icon" 
  android:label="@string/app_name"
  android:configChanges="orientation"       
  android:screenOrientation="portrait">

尝试将 tragetSDKVersionMarshmallow 更改为 Lollipop

对我有用。