当我搞砸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>