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


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

java.lang.RuntimeException:Unable to start activity ComponentInfo{net.maipeijian.xiaobihuan/com.etop.EtoVinActivity}: java.lang.IllegalStateException: Only fullscreen activities can request orientation


原因是:

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

void setRequestedOrientation(int requestedOrientation) {        if (ActivityInfo.isFixedOrientation(requestedOrientation) && !fullscreen

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

解决办法:

1.targetSdkVersion <=26 即可

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

void setRequestedOrientation(int requestedOrientation) {        if (ActivityInfo.isFixedOrientation(requestedOrientation) && !fullscreen

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

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

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

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

//8.1不能使用透明主题

 if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES. O) {

this.setTheme(R.style.A);//不透明

        }else {

this.setTheme(R.style.B);//透明主题

        }

如果使用该方法:

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

super.onCreate(savedInstanceState);

设置主题代码(setTheme)

setContentView(R.layout.activity);

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

 android:theme="@style/NoTitleDialog"

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容