Android 8.0 的填坑(透明的activity崩溃)

时间:2025-01-27 09:54:12

声明:本文转自:点击打开链接

一.透明的activity 不能继续使用

:Unable to start activity ComponentInfo{/}: : Only fullscreen activities can request orientation


原因是:

sdk27版本使用:if targetSdkVersion is >=27 ( > .VERSION_CODES.O) you get this error, they have changedActivityRecordin latest Android version adding this:

void setRequestedOrientation(int requestedOrientation) {        if ((requestedOrientation) && !fullscreen

                && > O) {            throw new IllegalStateException("Only fullscreen activities can request orientation");        ....        }

解决办法:

<=26 即可

  原因是sdk27版本使用:if targetSdkVersion is >=27 ( > .VERSION_CODES.O) you get this error, they have changed ActivityRecord in latest Android version adding this:

void setRequestedOrientation(int requestedOrientation) {        if ((requestedOrientation) && !fullscreen

                && > O) {            throw new IllegalStateException("Only fullscreen activities can request orientation");        ....        }

2.不需要使用坚屏的不要使用如下代码 

设置锁定坚屏setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);  或者  android:screenOrientation="portrait"

3.这种方式有点low  可是暂时过渡方案(判断版本号设置主题)

//8.1不能使用透明主题

 if (.SDK_INT >= Build.VERSION_CODES. O) {

();//不透明

        }else {

();//透明主题

        }

如果使用该方法:

1.设置主题代码放在  onCreate方法中的  

(savedInstanceState);

设置主题代码(setTheme)

setContentView();

 中activity不要使用设置主题代码

 android:theme="@style/NoTitleDialog"

我的GitHub     仅仅把自己的坑分享一下,欢迎指正。