使用非不透明活动定位Android API 27时锁定屏幕方向 [英] Lock screen orientation when targeting Android API 27 with a non-opaque activity

查看:162
本文介绍了使用非不透明活动定位Android API 27时锁定屏幕方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的活动有 android:windowIsTranslucent 设置为 true android: windowBackground 设置为半透明背景。我刚刚更改了目标并将sdk版本编译为27,现在启动此活动时出现异常:

I have an activity that has android:windowIsTranslucent set to true and android:windowBackground set to a translucent background. I just changed my target and compile sdk version to 27, and I get an exception when launching this activity now:

java.lang.IllegalStateException:只有全屏不透明的活动可以请求定位

由于这是一个新的sdk,它上面没有任何关于它的东西(它似乎这行代码的结果是: https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/android/app/Activity.java#987

Since this is a new sdk, there isn't anything online about it yet (and it seems to result from this line of code: https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/android/app/Activity.java#987 )

有没有办法解决这个问题?如果我从这个活动的清单中取出 android:screenOrientation =portrait,该应用程序不会崩溃,但我希望能够保持这样。

Is there any way to get around this? The app doesn't crash if I take out android:screenOrientation="portrait" from my manifest for this activity, but I would like to be able to keep it like that.

推荐答案

我也遇到了同样的问题。
正如其他人所说,如果我删除 android:screenOrientation =portrait或用 android:screenOrientation =unspecified覆盖它,那么异常就消失了。
前面活动的方向似乎跟在后面活动的方向上。

I also faced the same problem. As others said, If I deleted android:screenOrientation="portrait" or overrided it with android:screenOrientation="unspecified", then the exception was gone. And it seems that the front activity's orientation follows the behind activity's orientation.

我想到了。
如果前面的活动是透明的,后面的活动的方向是不同的,
显示变得很奇怪。
所以,我可以理解为什么这个检查逻辑被添加了
但是,我想知道为什么在Developer Preview 8.0.0中没有出现这个问题。

I thought about it. If the front activity is transparent and the behind activity's orientation is different, the display becomes strange. So, I can understand why this check logic was added However, I wonder that why this problem was not occurred in Developer Preview 8.0.0.

这篇关于使用非不透明活动定位Android API 27时锁定屏幕方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆