当我弄乱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中发生。请支持我进行修复。
非常感谢您的回答!
答案 0 :(得分:1)
如果阅读错误日志和堆栈跟踪,则会发现:
java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
因此,简单的解决方案是:从清单文件中删除该活动的以下行:
android:screenOrientation="portrait"
答案 1 :(得分:0)
在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);
}
谁知道这可能是一个错误。
如果您从框架themes.xml中搜索Theme.Translucent
样式,请(按)您将找到
<item name="android:windowIsTranslucent">true</item>