android 透明主题 crash,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     仅仅把自己的坑分享一下,欢迎指正。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值