I can't seem to show my own splash screen, every time I launch the app the default, blank splash screen is shown even though I've set up everything in launch_background.xml and the other files in res. I've also set up all the relevant icons in drawable and mipmap.
launch_background.xml:
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="#color/splash" />
</item>
<!-- You can insert your own image assets here -->
<item>
<bitmap
android:gravity="center"
android:src="#drawable/splash_icon" />
</item>
</layer-list>
styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="#android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">#drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="#android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#191919</color>
<color name="splash">#191919</color>
</resources>
<activity> tag in AndroidManifest.xml:
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="#style/LaunchTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="#drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
The splash screen should show an image and a different background color but instead it just shows the default blank white screen. I'm not using a custom splash screen for this. I just want at least the colors to change but even that is not working.
Also make the changes in drawable-v21/launch_background.xml. This will be used for Android API Level 21 or higher.
Pub.dev has a package that will create the native splash screens for you: flutter_native_splash
Related
Hello, i want to delete the banner that appears at the top of the MaterialApp only happens on Android, in iOs i don't have that issue.
I used the very_good cli
I tried to view if the android_manifest.xml have some information but i didn't find anything that could help me.
I am expecting to delete the black banner with the appName
This could be an AppBar which is located inside a Scaffold. Try looking for it in the project and delete it.
Alternatively this could be based on the android activitie's theme. In the android specific module, open the manifest.xml file and check which themes are used in the activities:
<manifest ...>
<application
...>
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
...
</activity>
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="#style/NormalTheme"
/>
...
</application>
</manifest>
In this case, flutter uses LaunchTheme and after the launch it applies NormalTheme.
Open then the styles.xml file (usually located at: android/app/src/main/res/values/styles.xml). Find the styles that match the styles which are used by the activity and check if they both inherit from a NoTitleBar style.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="#android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">#drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="#android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
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
Before, when my app first started up, there was a white screen. So I created a style with a black background in styles.xml and referenced it in my manifest:
<activity
android:name=".InitialScreen"
android:theme="#style/Theme.Transparent"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
styles.xml:
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:background">#000</item>
</style>
The black screen shows successfully, How can I show an ImageView in this style?
In your mipmap/drawables folder of your project add an image of your choice. Inside your style remove the background and add a windowBackground... inside reference your drawable or mipmap that you have added.
E.G:
I want my background to be a certain image, it's name will be background.png. I will go to the directory of my project and add this image to the drawables or mipmaps folder, depending on which you're using. In your style have this:
android:windowBackground="#drawable/background"
Or #mipmap/background depending on which you are using.
Why I have used windowBackground and not background
I have just recently done the same thing and realized that I had made a mistake when using background instead of windowBackground because if you have a layout/view which has no background specified it will use the same background. This will cause the background to repeat.
Hope I helped,
-Daniel
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.
I currently have an Activity for my splash screen. The following is the way I apply a theme to the activity:
<application
...
<activity
android:name=".activities.SplashActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
SplashTheme is defined as follows:
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:background">#drawable/splash_background</item>
</style>
splash_backround.xml is defined as follows:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap
android:src="#drawable/login_background"
android:tileMode="disabled" />
</item>
<item>
<bitmap
android:src="#drawable/login_siren"
android:tileMode="disabled"
android:gravity="bottom|center_horizontal" />
</item>
<item android:top="120dp">
<bitmap
android:src="#drawable/splash_welcome"
android:tileMode="disabled"
android:gravity="top|center_horizontal" />
</item>
I am not calling setContentView() in onCreate() of my SplashActivity class, so thing being displayed is what is set by the SplashTheme.
A situation has come up where I want to display an AlertDialog if something fails to load upon Application.onCreate(). The splash screen is displaying at the time I use this to build, create and show the AlertDialog. However, when I show the AlertDialog, it gets assigned the background from the Activity's theme. Even if I define a custom style for the AlertDialog (via android:alertDialogTheme or android:alertDialogStyle) that explicitly defines a different background, it gets overruled by the background defined by the activity. As a result, I've changed SplashTheme to the following:
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash_background</item>
</style>
This now releases control of the alert dialog background as I am not explicitly setting android:background in my Activity theme. However, the window background does not account for the status bar (i.e. the background applies underneath the status bar as well). As a result, I get a bit of jump when the splash screen transitions to the next activity that uses this same background in its layout (due to accounting for the status bar). So, this solution still isn't working as I'd like.
If I do use the original SplashTheme (where I define android:background), is there a way to override the theme's defined android:background for an AlertDialog?
It is not possible to change a theme of activity once it is applied.
Is there a way to override the theme's defined android:background for an AlertDialog?
AlertDialog has a constructor, which accepts themeResId as an input. From docs of AlertDialog (Context context, int themeResId):
Creates an alert dialog that uses an explicit theme resource.
Create a custom theme, overriding android:background attribute, then create AlertDialog using newly created theme:
Dialog dialog = new AlertDialog(context, R.style.my_dialog_theme);