此活动需要 'android:screenOrientation="unspecified"' 或 '"fullSensor"'

Bur*_*rak 58 android android-studio

我将我的 Android Studio 升级到 3.6.0。现在,我的Manifest.xml文件中出现以下错误。

此活动需要 'android:screenOrientation="unspecified"' 或 '"fullSensor"',以便用户可以在任何方向使用该应用程序,并在 Chrome 操作系统设备上提供出色的体验。

我应该将其转换为“fullSensor”吗?我怎样才能摆脱这个问题?

我的活动方向是纵向。我想在我的活动中继续使用纵向。

Nit*_*yal 73

This is a kind of warning to inform developers that for big screen devices it is not good to restrict the orientation. However if your application only supports portrait mode then this warning can be disabled by doing the following.

Mac: Android Studio -> Preferences

Windows: File -> Settings

Then:

  1. Search for "chrome"
  2. Uncheck "Activity is locked to an orientation"
  3. Apply and ok.

Unchecking step screen shot 取消选中步骤屏幕截图以禁用警告

这只会删除当前系统的警告。因此,此更改不会影响在同一项目上工作的其他用户。他们仍然会看到相同的警告。在某种程度上,当每个人都了解此警告时,最好对本地系统进行此更改。但是,如果我们想在项目级别删除此警告,则可以使用以下方法:添加tools:ignore="LockedOrientationActivity"Android 清单文件的清单标记。例如

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
tools:ignore="LockedOrientationActivity"
Run Code Online (Sandbox Code Playgroud)

因此,这是您的个人偏好,无论您是希望每个开发人员都知道此警告,还是希望tools:ignore="LockedOrientationActivity"在清单中添加并为每个人静音此警告。我更喜欢启发大家:)


Soh*_*aib 45

鉴于您的应用程序仅支持portrait模式,您可以通过添加tools:ignore="LockedOrientationActivity"到所有活动或仅添加到<manifest>适用于所有活动的顶级标签来忽略这些错误。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:ignore="LockedOrientationActivity"
    ...
    ...
Run Code Online (Sandbox Code Playgroud)

  • 这应该是答案,因为接受的答案仅适用于本地用户。将忽略添加到清单中也允许其他开发人员忽略更改。 (4认同)

小智 7

将其添加到清单标记中:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="LockedOrientationActivity"
...
Run Code Online (Sandbox Code Playgroud)