[英]lock/unlock orientation
To lock my orientation to portrait, I use: 要将我的方向锁定为肖像,我使用:
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
I'm unsure what flag tells the activity to go back to relying on the device orientation. 我不确定哪个标志告诉活动回到依赖于设备方向。 I imagine it is one of these: 我想这是其中之一:
SCREEN_ORIENTATION_FULL_SENSOR SCREEN_ORIENTATION_FULL_SENSOR
SCREEN_ORIENTATION_SENSOR SCREEN_ORIENTATION_SENSOR
SCREEN_ORIENTATION_UNSPECIFIED SCREEN_ORIENTATION_UNSPECIFIED
SCREEN_ORIENTATION_USER SCREEN_ORIENTATION_USER
On another note, why isn't the android documentation open source? 另外请注意,为什么Android文档不是开源的? The documentation is completely lacking. 文档完全缺乏。 Very few of the functions and flags have useful descriptions. 很少有函数和标志有有用的描述。
根据http://developer.android.com/reference/android/R.attr.html#screenOrientation (如果你SCREEN_ORIENTATION_SENSOR
SCREEN_ORIENTATION_FULL_SENSOR
文档,screenOrientation就是那些值链接到的那些), SCREEN_ORIENTATION_SENSOR
或SCREEN_ORIENTATION_FULL_SENSOR
将会这样做,具体取决于多少您想要的灵活性 - 但是,我怀疑您真正想要的是返回默认设置,即SCREEN_ORIENTATION_UNSPECIFIED
以便它返回到系统默认设置,包括任何用户设置。
An easy fix for this that worked for me is to add a line to AndroidManifest.xml like so: 对我有用的一个简单的解决方法是在AndroidManifest.xml中添加一行,如下所示:
Add android:screenOrientation="portrait"> in the application section. 在应用程序部分添加android:screenOrientation =“portrait”>。
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".App"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
如果此活动的应用程序
manifest entry
的“android:immersive"
属性设置为“true
”,则ActivityInfo.flags
成员始终设置其FLAG_IMMERSIVE位,即使沉浸模式在运行时使用“setImmersive()
更改”setImmersive()
“ 方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.