android - 无法从 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)上旋转为横向。我怎样才能让它保持纵向?
解决方案
您应该将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>
推荐阅读
- list - 如何将可遍历的函数应用于一个值
- python - 尝试使用范围在 csv 文件中创建序列,但只获取序列中的最后一个数字
- php - 清理控制台命令帮助输出
- python - Matplot:交互式重绘 axvline?
- azure - 创建 Azure My SQL - 无法创建可用的服务器名称
- database - 连接关闭时 aws lambda 崩溃
- c - printf 显示错误的数字
- reactjs - 使用依赖于状态逻辑的 HOC 重用 React 组件
- javascript - 如何隐藏/显示 html 表单字段(如果用户说是,则显示一个输出,如果他们说不,则显示不同的输出)?
- python - 有没有办法将 csv 文件从 github 自动导入到我的 jupyter notebook