应用主题在Oreo 8.1设备上崩溃

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了应用主题在Oreo 8.1设备上崩溃相关的知识,希望对你有一定的参考价值。

当我搞砸Oreo(8.1)设备中发生的崩溃应用主题时。这是我的代码,请检查一下。

  <activity
            android:name=".Menu_Activity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTranslTheme" />

<style name="AppTranslTheme" parent="android:Theme.Translucent.NoTitleBar">

当我删除android:theme时,应用程序没有崩溃。但我错过了屏幕的透明度。我也需要在Oreo发生崩溃。请支持我解决它。

您的回答非常感谢!!!

答案

如果您阅读错误日志和堆栈跟踪,您会发现:

java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation

因此,简单的解决方案是:从该活动的清单文件中删除以下行:

android:screenOrientation="portrait"
另一答案

在android Oreo中,如果样式(或父样式)具有以下行,则无法仅使用XML更改Activity的方向:

<item name="android:windowIsTranslucent">true</item>

首先删除

android:screenOrientation="portrait"

并在java文件中写代码如下:

    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

可能是它的一个错误,谁知道。

如果你从framework themes.xml搜索Theme.Translucent样式,(按)你会发现

<item name="android:windowIsTranslucent">true</item>

以上是关于应用主题在Oreo 8.1设备上崩溃的主要内容,如果未能解决你的问题,请参考以下文章