Android状态栏在启动屏幕中隐藏/更改颜色 [英] Android status bar hide/change color in splash screen

查看:62
本文介绍了Android状态栏在启动屏幕中隐藏/更改颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照本教程在我的应用中实现了一个无布局的启动屏幕:

I implemented a layout-less splash screen in my app following this tutorial: https://www.bignerdranch.com/blog/splash-screens-the-right-way/

我设法为MainActivity更改状态栏的颜色,甚至使用主题使其全屏显示.但是,我尝试过的所有方法都无法与初始屏幕一起使用.也许是因为它不使用布局,而是直接将可绘制对象用作背景:

I managed to change the color of the status bar for my MainActivity and even to make it fullscreen using a theme. However none of the methods I've tried are working with the splash screen. Maybe it's because it doesn't use a layout but directly a drawable as background:

<style
    name="AppTheme"
    parent="@android:style/Theme.Material.Light.NoActionBar">

    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColor">@color/textColor</item>
    <item name="iconColor">@color/iconColor</item>
    <item name="android:statusBarColor">@color/colorPrimaryDark</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>

<style
    name="SplashTheme"
    parent="AppTheme">

    <item name="android:windowBackground">@drawable/splash_screen</item>
</style>

我尝试使用全屏主题,在活动使用的主题中设置android:statusBarColor,我还尝试了以下两段代码:

I tried using a Fullscreen theme, setting android:statusBarColor in the theme used by the activity, I also tried the two following bits of code:

View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);

Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(ContextCompat.getColor(this, android.R.color.transparent));

这4种方法适用于我的正常活动,但不适用于初始屏幕.我有什么可以做的吗?

These 4 methods are working for my normal activity but not for the splash screen. Is there anything I can do?

我的目标是minSdkVersion 23

I'm targetting minSdkVersion 23

推荐答案

好吧,经过更多的实验,事实证明我遇到了某种缓存问题.我尝试将我的应用程序安装在另一部手机上,并且按预期工作,而在我安装该应用程序的第一部手机上,该应用程序未更新.因此,您已经知道,android:statusBarColor的简单解决方案足以使其正常工作.

Okay, after more experiments, it turns out I had some sort of a cache problem. I tried installing my app on another phone and it worked as intended, whereas on the first phone I installed the app, it's not updating. So just so you know, the simple solution of android:statusBarColor is enough to make it work.

现在有关该缓存问题,这不是我第一次在该屏幕上使用它,这一定是没有布局和可绘制背景作为特殊条件的特殊条件.我尝试使Android Studio中的缓存无效,我清理并重建了项目,然后在手机上卸载了该应用程序,但没有任何效果.因此,如果您处于这种状态,请尝试尝试在另一部手机上运行您的应用程序,以检查您的解决方案是否已经运行,而不是在设备上进行更新.

Now about that cache problem, it's not the first time I have it with that screen, it must be the particular condition of having no layout and a drawable as a background. I tried invalidating the cache in Android Studio, I cleaned and rebuilt the project, I uninstalled the app on the phone but nothing works. So if you are in this cofiguration, just try to run your app on another phone if you can, just to check that your solution isn't already working, just not updating on your device.

这篇关于Android状态栏在启动屏幕中隐藏/更改颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆