首页 > 解决方案 > 无法从 Android 清单锁定屏幕旋转

问题描述

我想让我的应用程序处于纵向模式。仅使用一个基本的空活动,我将前两行添加到清单中的应用程序信息中:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.lxg.golf">

    <application

        android:resizeableActivity="false"
        android:screenOrientation="portrait"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Golf">

        <activity android:name=".MainActivity">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

但它仍然在我的设备(Galaxy S8,Android 版本 9)上旋转为横向。我怎样才能让它保持纵向?

标签: android

解决方案


您应该将screenOrientation属性添加到每个活动:

        <activity android:name=".MainActivity"
                  android:screenOrientation ="portrait">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


推荐阅读