How do I make an android splash screen for flutter? - android

I have seen a lot of articles and youtube videos and tried everything however i cannot change the android splash screen color
drawable/launch_background.xml:
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/background" />
<!-- You can insert your own image assets here -->
<item>
<bitmap
android:gravity="center"
android:src="#drawable/launch_image" />
</item>
</layer-list>
values/colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background">#2196F3</color>
</resources>
Production Build with key output:

It is really simple to create Native splash screens using this package.
https://pub.dev/packages/flutter_native_splash
add this package in your dev-dependencies
dev_dependencies:
flutter_native_splash: ^0.2.9
add the following code in your YAML file.
flutter_native_splash:
color: "#42a5f5"
image: "assets/splash.png"
and run the command
flutter pub run flutter_native_splash:create
That's all, This package will take care of all the process.
FYI: This creates native splash screens for both Android and iOS, but
you can control it too. if you want to create only for Android, you
can set the iOS property to false. Documentation of the Package is
pretty clear.

Related

Flutter Android Splash Screen always black

Oddly enough my android apps splash screen is white on my android emulator but black on my personal phone when I load the APK on it.
When I went to investigate I see this in the Android manifest:
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="#style/NormalTheme"
/>
And when I go to res drawable I see a file called launch_background.xml which sounds promising.
But when I look inside it, it shows:
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#android:color/white" />
<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="#mipmap/launch_image" />
</item> -->
</layer-list>
Which is odd because it says its white. So I am not sure what I am missing on why my cell phone boots it black. I want to make the splash screen background color white for everyone.
create a new file named color.xml in values in given route => your_project_name\android\app\src\main\res\values and add this code.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background_color">#ffffff</color>
</resources>
after that use this line in both drwables under layer-list tag
<item android:drawable="#color/background_color" />
this will solve your issue
If your Emulator shows a white screen and your phone shows dark maybe it's because of the dark theme on your mobile phone
in your phone settings change the dark mode to Light mode
settings -> display -> Lightmode
if your phone has a dark theme all the white colors will appear as black hope it helps
maybe you can add a white image ;
Android/App/res/drawable/white.png
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#android:color/white" />
<item>
<bitmap
android:gravity="center"
android:src="#drawable/white" />
</item>
</layer-list>
Are you using a dark theme on your phone? Like, do your Messenger app, email app etc have a dark background?
And if so, if you change that to a light theme, does that give your splash screen a white background?
(I was thinking since your Android manifest talks about "normal theme"... That's gotta be the overall theme of the phone, right? Perhaps remove that from the manifest?)
Also, if you follow this method to set your splash screen, including background color, does it help?:
https://youtu.be/JVpFNfnuOZM

Android: How to configure a loading screen with background color and centered image

So, I've almost finished my Android app using Flutter, and now I've just created the icons using Android studio tools (right click on "res" folder -> new -> image asset...).
So far so good, but now I'm having an hard time trying to figure out how to put the app icon in the loading screen.
What I did so far is:
Creating a styles.xml under res/values:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="#android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">#drawable/launch_background</item>
</style>
</resources>
Creating a launch_background.xml in res/drawable:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="center">
<item android:drawable="#android:color/holo_green_light" />
<item>
<bitmap android:src="#mipmap/ic_launcher" />
</item>
</layer-list>
but the asset #mipmap/ic_launcher is not resolved... I have no idea how to specify it correctly!
In AndroidManifest.xml I've defined the theme as android:theme="#style/LaunchTheme" and the icon as android:icon="#mipmap/ic_launcher"... and since the icon is correctly used by the app once installed, I don't get why in the manisfest is resolved and in the other file is not... what I'm supposed to do?
I like the simplicity of Eric's response, additionally, there is thorough documentation on the flutter.dev website on how to do this without the additional package.
https://flutter.dev/docs/development/ui/splash-screen/android-splash-screen
So, after several attempts I've solved in by using the following configurations:
styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="#android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">#drawable/launch_background</item>
</style>
<color name="white">#FFFFFF</color>
</resources>
launch_background.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="center">
<item android:drawable="#color/white" />
<item
android:width="400px"
android:height="400px"
android:drawable="#mipmap/ic_launcher"
android:gravity="center" />
</layer-list>
The relevant difference is that I'm now using a drawable for the logo instead of a bitmap. Currently, it works perfectly in release mode (flutter clean && flutter run --release), even though in debug mode a black screen is visible for few milliseconds before the main Flutter widget is actually rendered.
You can use a dev dependencies package: https://pub.dev/packages/flutter_native_splash
Add on pubspec.yaml
dev_dependencies:
flutter_native_splash: ^0.1.9
declare your icon launcher and color
flutter_native_splash:
image: 'assets/ic_launcher.png'
color: "#36133d"
and them run:
flutter pub get
flutter pub run flutter_native_splash:create

How to create a gradient color background for splash screen in Flutter?

I'm working on the splash screen for my Flutter app, and in drawable folder I have to create a file called colors.xml in order to change background color for my splash screen. I'm finding it hard to make it a gradient color. My intention is to create a gradient background color that would start at the top left and end at bottom right, using two different colors. Does anyone have an example of how to do that in Flutter? Thanks!
P.S. An is there a difference in the process for android and ios?
1 In \android\app\src\main\res\drawable\launch_background.xml
change this :
<item android:drawable="#android:color/white" />
to :
<item android:drawable="#drawable/gradient_background" />
2 Create this file \android\app\src\main\res\values\colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="gradientstart">#3587d0</color>
<color name="gradientend">#36f1d3</color>
</resources>
3 Finally, create this file \android\app\src\main\res\drawable\gradient_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#color/gradientstart"
android:endColor="#color/gradientend"
android:angle="90"/>
</shape>
For Android first define two color in your colors.xml:
<color name="gradientstart">#888888</color>
<color name="gradientend">#111111</color>
then in \android\app\src\main\res\drawable\launch_background.xml just replace this:
<item android:drawable="#color/background" />
to this:
<gradient android:startColor="#color/gradientstart" android:endColor="#color/gradientend" android:angle="315"/>
and for ios according to this question
If your gradient is a simple vertical or horizontal gradient, and
you’re really concerned about asset size, you can define a very narrow
image and then add an image view with “scale to fill” content mode.
But these images are so small anyway, the amount of space saved will
be negligible, so I’m not sure it’s worth worrying about.
I found use of flutter_native_splash much more easy and direct. Here's a link on the steps to creating one. First design your desired gradient as an image and instead of adding color, add a background_image on the pubspec.yaml file.
Something like:
flutter_native_splash:
image: ""
background_image: "assets/my_splash_background.png"

How to make a gradient splash screen using TWA meta-tags?

Following the instructions at Google Developers site, I sucessfuly created my splash screen.
Using the meta-tag:
<meta-data
android:name="android.support.customtabs.trusted.SPLASH_SCREEN_BACKGROUND_COLOR"
android:resource="#color/colorPrimary"/>
We can display a color in our app, but can we display a gradient?
I have tried to create a xml gradient and then reference it with android:background instead of android:resource, but it didn't work.
My gradient.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:type="linear"
android:startColor="#color/color1"
android:endColor="#color/color2"
android:angle="135" />
</shape>
My colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="color1">#fafafa</color>
<color name="color2">#212121</color>
</resources>
And the snipet added in the manifest.
android:background="#drawable/gradient"
As said, I just want to be able to use splash screen gradients using native TWA meta-tags, if possible. I got errors when I try to install the .apk (invalid package).
Reference link: Google Dev Splash Screen
Only flat colors can be used as background for a Trusted Web Activity splash screen and drawables are not currently accepted in the Splash Screen.

Qt Quick Controls 2 Splash Screen

I am developing a mobile app using Qt Quick Controls 2, and would like to display a splash screen while the app is being initialised. Currently, this is what the user sees when the app is started:
A dark background with the name of the app as a header.
A blank, white background.
The application window.
In that order for an Android 6 Marshmallow smartphone. If I add the splash screen to the application window, perhaps in a stack view, and then transition to the actual contents when it is initialised, (1) and (2) would still remain, right? Is there any way to tell Qt to display the splash screen instead of (1) and (2), or at least instead of (1)?
First in _yourProject_/android/res/drawable create a splash.xml file:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<solid android:color="#353535"/>
</shape>
</item>
<item>
<bitmap android:src="#drawable/icon" android:gravity="center" />
</item>
</layer-list>
That sets the splash screen background color and icon that will be centered on the screen.
Then in /android/res/values create a theme.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="#android:style/Theme.DeviceDefault.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash</item>
</style>
</resources>
Then in the android manifest file, on the line <activity android:configChanges= add android:theme="#style/AppTheme" after the label settings, then scroll down to the <!-- Splash screen --> section and uncomment and modify the line:
<meta-data android:name="android.app.splash_screen_drawable" android:resource="#drawable/splash"/>
Replace the #353535 color with whatever the color of your application window is set to for smooth transition. The image is optional.
I just tested that and it works. Perhaps someone else will be able to provide a solution for iOS.

Categories

Resources