解决部分android手机页面跳转的黑白屏、闪屏、显示桌面背景问题

解决部分android手机页面跳转的黑白屏、闪屏、显示桌面背景问题

关于

  今天在查看登录页面美观度的时候意外发现手上的oppo手机在页面跳转的时候会有明显的显示桌面背景的问题,先看一下有问题的页面跳转(此篇文章也会作为简易音乐博客系列之一):
在这里插入图片描述

修改后的方案效果图

在这里插入图片描述

  通过gif可以看到有一瞬间的手机背景的展示问题,当然了,黑白屏的问题在本文一开始就解决了:

 <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowIsTranslucent">true</item>
        <!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色-->
        <item name="android:statusBarColor" tools:ignore="NewApi">#00000000</item>
    </style>
 <style name="ThemeSplash" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowTranslucentNavigation" tools:ignore="NewApi">true</item>
        <!--解决部分手机隐藏状态栏顶部出现小黑条的问题-->
        <item name="android:windowLayoutInDisplayCutoutMode" tools:ignore="NewApi">shortEdges</item>
        <!--解决白屏问题-->
        <item name="android:windowBackground">@color/colorAccent</item>
        <item name="android:windowFullscreen">true</item>
        <!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色-->
        <item name="android:statusBarColor" tools:ignore="NewApi">#00000000</item>
    </style>

问题思路及解决办法

  上图gif里面总共三个页面,SplashActivity.javaLoginSelectActivity.javaLoginActivity.java,对应界面如下图:

  我还特意为此去学习了下如何使图片并排显示。
其中第一个SplashActivity.java是启动页面,对应上面的ThemeSplash样式,跳转LoginSelectActivity.java页面代码如下:

//ARouter路由
 ARouter.getInstance()
                        .build(Config.ROUTE_LOGINSELECT)//跳转到选择按钮页面
                        .withFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK)
                        .navigation(SplashActivity.this);
                       finish();

  想着是不是因为跳转的时候清空了栈,导致页面是从桌面启动的,去掉Intent.FLAG_ACTIVITY_CLEAR_TASK标签:

//ARouter路由
 ARouter.getInstance()
                        .build(Config.ROUTE_LOGINSELECT)//跳转到选择按钮页面
                        .withFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                        .navigation(SplashActivity.this);
                       finish();

  修改了之后还是显示了桌面背景,继续修改,想着给AppTheme添加一个不透明的背景呢,修改如下:

 <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowIsTranslucent">true</item>
        <!--解决页面跳转的状态栏白屏问题-->
        <item name="android:windowBackground">@color/colorAccent</item>
        <!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色-->
        <item name="android:statusBarColor" tools:ignore="NewApi">#00000000</item>
    </style>

  修改跳转代码:

 ARouter.getInstance()
                        .build(Config.ROUTE_LOGINSELECT)//跳转到选择按钮页面
                        .withFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK)
                        .navigation(SplashActivity.this);
                        //去掉finish();方法 因为跳转过程中销毁了前一个页面,导致页面显示了透明背景即显示了手机桌面背景

最终方案

  贴下最终完整代码吧,首先是样式styles.xml:

<resources xmlns:tools="http://schemas.android.com/tools">

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowIsTranslucent">true</item>
        <!--解决页面跳转的状态栏白屏问题-->
        <item name="android:windowBackground">@color/colorAccent</item>
        <!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色-->
        <item name="android:statusBarColor" tools:ignore="NewApi">#00000000</item>
    </style>
    <!--启动页样式-->
    <style name="ThemeSplash" parent="AppTheme">
       <item name="android:windowTranslucentNavigation" tools:ignore="NewApi">true</item>
        <!--解决部分手机隐藏状态栏顶部出现小黑条的问题-->
        <item name="android:windowLayoutInDisplayCutoutMode" tools:ignore="NewApi">shortEdges</item>
        <item name="android:windowFullscreen">true</item>
    </style>

</resources>

SplashActivity的跳转:

ARouter.getInstance()
                        .build(Config.ROUTE_LOGINSELECT)//跳转到选择按钮页面
                        .withFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                        .navigation(SplashActivity.this);
                overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);//转场动画
                
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雪の星空朝酱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值