0

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

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>

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));

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

EDIT: I'm targetting minSdkVersion 23

Gaetan L.
  • 649
  • 6
  • 20

4 Answers4

8

Use <item name="android:windowFullscreen">true</item>

<style
    name="SplashTheme"
    parent="AppTheme">
    <item name="android:windowFullscreen">true</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowBackground">@drawable/splash_screen</item>
</style>
Ramana V V K
  • 1,245
  • 15
  • 24
  • 1
    Doesn't work :( Status bar is still displayed in grey. – Gaetan L. Jun 04 '17 at 16:28
  • add this as well in style " false true " or else change the parent value to "Theme.AppCompat.Light.NoActionBar" then It should work – Ramana V V K Jun 04 '17 at 16:39
  • No that's not the problem, the parent theme is already NoActionBar anyway. I really think the problem is related to the fact that the activity has no layout. – Gaetan L. Jun 04 '17 at 17:02
2

Use this in your theme.xml

<item name="android:navigationBarColor">@color/black</item>
m4n0
  • 29,823
  • 27
  • 76
  • 89
Harshad pk
  • 71
  • 2
  • 4
1

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.

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.

Gaetan L.
  • 649
  • 6
  • 20
0

I've had the similar problem few months ago. I've managed to solve this by using following codes.

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

Use the above code in your java file after setContentView.

Then use this in the manifest file for the activity that you are trying to hide the title bar.

android:theme="@style/Theme.AppCompat.NoActionBar"

To change the color of the title bar, you can use the following line of code,

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#000000")));

Replace the hex code of the color that you want to add to the title bar in value part of the code.

  • 1
    I think you're mistaking the Status Bar for the Action Bar, the Status Bar is the small bar where notifications, battery and time are displayed. – Gaetan L. Jun 04 '17 at 18:32
  • To change the color of a status bar, use this code. In your case, you are trying to set it to Transparent so by using this, you can get a transparent status bar. getWindow().setStatusBarColor(Color.TRANSPARENT); PS -This method just works on API 19 and above. If that doesn't work, try this code segment in styles.xml true –  Jun 04 '17 at 18:42
  • You can also do this in in /res/values-v21/styles.xml: @android:color/transparent –  Jun 04 '17 at 18:42