I have integrated splash screen into my app from android manifest I gave it a newly made SplashTheme and whenever the onActivityCreated called I change it to the one that is needed. Now , in splash.xml file which you can see below:
<item>
<color android:color="#color/colorPrimary" />
</item>
<item>
<bitmap
android:gravity="center"
android:src="#mipmap/ic_launcher" />
</item>
I put my launcher ic_launcher in the center but when the device in which the app is installed uses round icons the splash screen still shows the "original" icon. I know because I put here ic_launcher instead of ic_launcher_round but I would like to make this part dynamic, to recognize if the devices uses round icons put ic_launcher_round and the opposite.
Here is the part of my AndroidManifest.xml:
Afaik, you cannot achieve the behavior you expect, simply because there does not exist an API, that would provide you whether current launcher uses round icon or a default icon.
Instead, you should construct your splash screen in a way, that is not dependent on the default launcher implementation of the device. Normally, you should have the same image regardless launcher uses round or normal icons.
Leave launcher icons aside and create a resource specifically for splash screen.
Related
Here's the code in 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="#android:color/black" />
<!-- You can insert your own image assets here -->
<item>
<bitmap
android:gravity="center"
android:src="#drawable/applogo" />
</item>
</layer-list>
I have changed the color to 'black'- yet I get a white splash screen, neither do the logo shows up.
I have placed the logo (png) in the drawable folder. Can anyone help me with this?
first, you need 2 files to make this work, first are the files in the drawable and drawable-v21 folders they should have
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/background_color" />
<item>
<bitmap android:gravity="center" android:src="#mipmap/launch_icon" />
</item>
</layer-list>
#color/background_color
is a custom color style for android which you would have to create it next
#mipmap/launch_icon
is a custom icon image you have in your mipmap folders you can create the sizes by using https://appicon.co
and the second file will create as a colors.xml in the values and values-night folder this file will carry the color you want to use
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background_color">#000000</color>
</resources>
I think you want to remove the white screen at app boot time. Check This library, you can use color or logo image anything else instead of the white screen.
Click this Link
Here is the Preview
for android
open launch_background.xml file inside the Res folder and add one new splash screen image in the drawable folder. Now change code in two places. See tutorial example here
Edit this launch_background.xml by adding a new item and set the splash screen image as an item value.
For iOS app
Open flutter project on Xcode for Adding splash screen to flutter ios app. To open the iOS module on Xcode, open android studio and on the top menu select tools. Go to flutter –> open ios module on Xcode.
On Xcode window, Click on Runner-> Runner -> Assets.xcassets folder. Here you can see LaunchImage paste your splash screen image with all three different dimensions in this folder.
Open LaunchScreen.storyboard
Again on the left side menu just below the Assets.xcassets folder, you will see LaunchScreen.Storyboard. Click on view controller scene -> view controller -> view. Note: – select (click on ) view only don’t click on LaunchImage. You already paste the new splash screen in the LaunchImage folder in the previous step. So you will see the same new image here in this window. When you select (click on ) view then on the right side window you can see options to change view settings like content mode, background, alpha etc. change the background colour as you want and set content mode to scale to fill.
Adjust Splash Screen
You can adjust the splash screen position, size & background colour on the same window. Just click on launchImage OR select the image on the preview window. You can resize the image and can adjust the image position. On the Right side window, you can make another set as well.
iOS App Splash Screen is Ready.
Now flutter white splash screen problem has been resolved successfully for both android and iOS. You can change the flutter splash screen background color as per your requirements.
Currently using the layer-list to achieve a splash screen with a drawable at the center. The app is targetting API 23+ so using bitmap is not mandatory unless it's necessary for what am trying to do. Basically I'm trying to pull off something similar to WhatsApp's new splash screen where the company reference is placed at the bottom of the screen.
But for some reason, the second image is not being shown at all even though it's visible in the Android Studio preview distorted. What I have currently is:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/black700" />
<item
android:drawable="#drawable/ic_app_icon"
android:gravity="center" />
<item
android:drawable="#drawable/ic_company_mark"
android:gravity="bottom|center" />
</layer-list>
As stated in the comments I've noticed that the bottom item depends on the phone resolution on some phones. Why it depends on the resolution, I don't know.
To work around you can add padding at the bottom
<item android:bottom="50dp">
for your bottom item in your layer-list and it will show up.
I haven't found a way to dynamically set the value depending on something and therefore used a value which "looks good" for most display resolutions.
In the Kotlin based Android app, I have a Splash screen which I have developed with the Style attributes as below code:
Drawable File(This one is for Light, Same is for Dark with different gradient color codes):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:angle="270"
android:endColor="#43dc91"
android:startColor="#29abe2" />
</shape>
</item>
<item>
<bitmap
android:gravity="center"
android:src="#drawable/My_Image" />
</item>
</layer-list>
Style also has 2 style.xml files - one for dark and one for light:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash_back</item>
</style>
And it is called from the Manifest:
<activity
android:name="com.app.ui.splash.SplashActivity"
android:theme="#style/SplashTheme">
Now the issue is that when my app switches to the dark mode from light mode, user will close the app and then open the app again, for 2 seconds, it still shows the light mode splash and after 2 seconds, the dark mode splash will load.
This could happen because when the app is loaded in the splash activity -> Oncreate, I am verifying that if the app has a preference of dark theme then load the dark mode and then it switch my app to dark mode as below:
private fun setAppTheme() {
when {
userHolder.theme != null -> {
if (userHolder.theme == string_(R.string.text_dark_mode))
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
else AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
else -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
}
}
}
What to do in such a case? How to load dark mode splash in the first instance itself while loading it from style and drawable?
I faced the same issue as you and finally, I realized that at the moment there is no way to do that for Android versions not containing the dark mode feature. So for older versions, you will see the light splash screen even if you enable your dark mode theme in your app with
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
You can test this behavior too in many other applications like WhatsApp and Messenger in Android 9 and below, it will show you the light splash screen even if you turned on the dark mode inside the app. May it helps someone for saving his time.
There is actually a simple solution to this. Make your dark mode splash screen your default. I personally believe that the seeming convention of white/brightly colored splash screens is terrible.
I hate it when I open an app in a dark room and I'm blinded by for a couple of seconds as my eyes adjust. It should be industry standard not to have brightly colored splash screens. Use soft/darker hues for your default background.
I realize this is more of an opinion but it solves your problem on older devices by not having to choose as your default is already your darker splash screen.
I think this must have been added now.
Found the answer here:
Android Change branded launch background colors when theme is dark
TLDR; Add a separate drawable folder under a resource directory called drawable-night. This worked perfectly for me
I am trying out with Dark Mode Theme Support for Android 10 for my App.
I am able to work with all other things in Dark Mode except App Launcher Icon.
For reference, I was using below link
https://developer.android.com/guide/topics/ui/look-and-feel/darktheme
I know there is no such mention of App Icon change as per Day/Night theme changes.
Just for confirmation, need all your inputs on will it be possible to change the app icon as per change in theme from normal to dark and vice versa.
Thanks in advance.
Have you checked the Themes and styles section in documentation?
Your themes and styles should avoid hard-coded colors or icons
intended for use under a light theme. You should use theme attributes
(preferred) or night-qualified resources instead.
Here are the two most important theme attributes to know about:
?android:attr/textColorPrimary This is a general purpose text color. It is near-black in Light theme and near-white on Dark themes. It contains a disabled state.
?attr/colorControlNormal A general-purpose icon color. It contains a disabled state.
So the ?android:attr/textColorPrimary and ?attr/colorControlNormal will change based on the theme (black -> white & white -> black). I'm assuming we can set those colors as android:tint property to achieve the dark/white theme for vector icons. The con is your icons need to be black and white only.
To achieve Dark Mode for Icons in Android:
Create the separate resource folder named values-night
Inside values-night folder define your night theme (ex. theme.xml)
Define all the desired colours you want in Dark mode inside theme.xml
Now, inside your icon drawable define the icon tint attribute as follows-
<vector android:height="24dp" android:tint="?attr/colorPrimaryDark" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp"
Using the above code, the icon colour will change based on colours defined in Dark and Light mode theme in your project
Pictures:
res folder values-night
define your Dark mode theme
change icon tint attribute of your Icons
light mode
Dark mode
No, the app icon does not support dark mode.
Apart from the app icon, other images colour can be modified :
Try using
android:drawableTint="#color/black"
OR
app:tint="#color/black"
[
Add xml import by presing ALT+Enter or use following:
xmlns:app="http://schemas.android.com/apk/res-auto"
]
with your desired image.
UPDATE:
or Just use:
ivMyImageView.setColorFilter(ActivityCompat.getColor(context, android.R.color.holo_green_light))
PS:
(Attribute drawableTint is only used in API level 23 and higher)
I think it possible, just launcher doesn't support display it.
BTW, I created new color resource into values-night and values, eg:
<!-- values-night/colors.xml -->
<color name="icon_background">#000000</color>
<!-- values/colors.xml -->
<color name="icon_background">#FFFFFF</color>
Then set background color into app icon:
<!-- mipmap/ic_launcher.xml -->
...
<background android:drawable="#color/icon_background" />
...
<!-- mipmap/ic_launcher_round.xml -->
...
<background android:drawable="#color/icon_background" />
...
App's icon now change when toggle dark mode..., but only for app swicher (icon display on top of window), but lancher does't update...
I've tested on Android 11 on Pixel 4XL phone (using Google Launcher).
Anyone else?
Dark mode is not supported for app icons (launcher icons).
Reason for this:
Some resource qualifiers like locale/density/version code do not
change in day-to-day use and changing icons on those are supported.
But we do not recommend changing app icons and labels based on
frequently changing parameters and it is not supported at most places
in system UI. Users create a memory map between apps and their
corresponding icons/labels. Changing these frequently is disruptive to
the user.
There is an issue filed with google for this and the decision is:
Won't Fix (Intended Behavior)
Issue tracker: https://issuetracker.google.com/issues/147521650?pli=1
Well, you can use ure resource colors. Add night mode variation (right click values, New -> Values resource file, set file name "colors" and qualifier "Night mode". You can do variation of drawable specifically if you want.
The main drawback - it doesn't really stable. I don't know if it's just me, but I'm getting weird behaviour in emulator (sorry, can't test on device right now). Right after install icon is set with correct mode, but when you change to other it doesn't get updated. When you try to move icon it using current theme variation however.
Try to add mipmap-anydpi-v26 & mipmap-night-anydpi-v26 icons in your source code. I tried to add but is a little bit buggy. I theory icons support dark theme XD
Here is an example
You might be thinking this question is a duplicate of this one. But since then, Android Studio has been updated and the solution given there is not working anymore.
Why are we forced to have a background when creating an Image Asset? What's the reason behind this? How we are supposed to change the launcher_icon without having any background? I don't see any option to disable the background in Image Asset.
Alternatively, I use an empty background but this doesn't work in Full Bleed Layers:
<?xml version="1.0" encoding="utf-8"?>
<vector
android:height="108dp"
android:width="108dp"
android:viewportHeight="108"
android:viewportWidth="108"
xmlns:android="http://schemas.android.com/apk/res/android">
</vector>
Or, just remove the background, but this will add a white background in your launcher_icon:
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Remove the background here and leave the foreground -->
<foreground android:drawable="#drawable/ic_launcher_foreground"/>
</adaptive-icon>
Or, change icon type into Legacy Only and set shape to none:
Still, there's a white background in the launcher icon when installed.
So how can I get a transparent background or none for that matter, for my Launcher icon using Image Asset?
It is not a problem of the icon you created with Android Studio, but it's a problem related to your specific device you're testing the application on.
In fact, in the Image Asset if you specify the Shape to None, you get a trasparent background.
To address your problem, please try to use a different Home theme, like the Nova Launcher; you can change the home theme in Settings - Home.