仅在Android 8.0(API级别26)中将屏幕方向限制为纵向模式,而将Android Android 8.1(API级别27定位为目标)

问题描述 投票:3回答:1

分别在我的build.gradle(Module:app)文件中将compileSdkVersion 26targetSdkVersion 26升级为compileSdkVersion 27targetSdkVersion 27时,所有其他Android版本,但在Android 8.0(API级别26)模拟器中遇到以下错误:

由:java.lang.IllegalStateException引起:仅全屏不透明活动可以要求方向

删除android:screenOrientation="portrait"对我有用,但是现在我的屏幕旋转了(我不想这么做)。

再次切换回compileSdkVersion 26可以双向操作,即我没有任何错误,并且活动屏幕也仅限于纵向。

但是我的问题是,仅在Android 8.0(API级别26)中将屏幕方向限制为纵向模式,而将Android Android 8.1(API级别27)作为目标。

任何帮助将不胜感激。谢谢!!

android android-gradle-plugin android-manifest android-orientation android-8.0-oreo
1个回答
0
投票

在活动中添加以下行

android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity"

这里是MainActivity ### strong文本的示例

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

    <application
        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/AppTheme">

        <activity android:name=".MainActivity"
            android:screenOrientation="portrait"
            tools:ignore="LockedOrientationActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

© www.soinside.com 2019 - 2024. All rights reserved.