Reputation: 665
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
Upvotes: 0
Views: 10339
Reputation: 89
Use this in your theme.xml
<item name="android:navigationBarColor">@color/black</item>
Upvotes: 2
Reputation: 665
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.
Upvotes: 1
Reputation:
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.
Upvotes: 0
Reputation: 1251
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>
Upvotes: 8