I've got a problem with my flutter app when I want to resume my app on android. So I tested the example flutter app that gets generated, but the problem also exists there. I modified only the launch_background.xml file to change the background color to black and put the launcher icon to the splash screen.
The problem is that when I resume the app after I paused it, the splash screen is visible for a short period of time. The gif below shows the problem.
Does anyone know a solution for this or do I have to deal with that?
Thanks in advance
--EDIT--
Changes to the styles.xml in Android
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="#android:style/Theme.Black.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>
</resources>
Try using flutter_native_splash. I use it in my all projects and it works flawlessly. Their doc says :
Automatically generates native code for adding splash screens in Android and iOS. Customize with specific platform, background color and splash image.
Make sure to run the package with below line after you make all the changes :
flutter pub pub run flutter_native_splash:create
Related
Flutter Splash Screen
Pubspec.YAML code-
flutter_native_splash: ^2.0.1+1
flutter_native_splash:
image: assets/images/splashScreen.png
color: "#c988be"
Styles.xml -
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>
<item name="android:windowFullscreen">true</item>
</style>
if you want to hide the action bar you need to go to app manifests and then set the theme of the splash screen layout to no action bar as so:
android:theme="#style/Theme.AppCompat.NoActionBar"
if you want also to hide the status bar you use flags in the splash screen activity as so:
#Suppress("DEPRECATION")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.insetsController?.hide(WindowInsets.Type.statusBars())
}else{
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
}
You have to check this package flutter_native_splash, in this package you just need to set your splash screen image path.
Add this code into your pubspec.yaml file
flutter_native_splash:
background_image: "assets/images/splash_bg.png"
Make sure to run this command:
flutter pub run flutter_native_splash:create
When you config flutter_native_splash like this:
After run command: "flutter pub run flutter_native_splash:create", flutter_native_splash package will generate some drawable files on android/ios folder like below:
In android, to display that image in fullscreen. open generated launch_background file and change gravity="center" to gravity="fill"
After modify gravity, run your app again, you will see splash screen displayed as full screen.
hello Vietnamese compatriot Trung Đoan, in my case just leave the "image: assets/splash.png" is fine, add
<item>
<bitmap android:gravity="center" android:src="#drawable/splash"/>
</item>
in launch_background.xml file, and do the rest as you said, thank you <3
Unfortunately Android does not have good support for filling the screen without distorting the image. One way you can fix this problem is to make the splash screen image larger than it needs to be, set it as centered, and then the splash image will be clipped by the size of the screen.
I was recently trying to add a splash screen to my android app that I am trying to develop. But no matter what changes I make changes are not getting reflected. I am new to flutter to I am including a lot of code. Here is the code -
values>colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background_color">#FFCC00</color>
</resources>
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_color" />
<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="#drawable/welcome" />
</item> -->
</layer-list>
I am using flutter channel 'master' as Android Studio 4.1.2 is not supported in channel 'stable'
Please inform me if any other code is required. Thanks in advance.
I tried a lot of stuff. Wasted nearly 14 hours, to realize that Android Studio 4.1.2, has some sort of problem with flutter doctor as of 12/2/2021. So I switched back to Android Studio 4.0 and re-installed the flutter SDK. This solved the problem for me. As far as, I am aware of the issue, it was due to different unsupported versions of Android Studio and Flutter. Maybe in the future, smart guys at google sort this out :)
Just want to drop this here for those who may have this issue with React Native. What solved it for me was slightly renaming the splash screen file inside my assets folder. It was splash.png, after I made changes to it and overrode the file, the old splash screen kept showing.
Reloading, restarting the server, clearing cache, none solved it.
When I finally renamed the file to splashscreen.png and reload. Viola!
I have a freshly created Flutter app, and I configured my splash screen to display some background color and app icon in the middle.
By default, Android splash starts with status bar that looks dark semi-transparent. I wanted to change the color to be the same as splash background. I managed do this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="#android:style/Theme.NoTitleBar">
<item name="android:windowBackground">#drawable/launch_background</item>
<item name="android:colorPrimaryDark">#color/splash_color</item>
<item name="android:statusBarColor">#color/splash_color</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
</resources>
It works, but only for the few first milliseconds. After that, the logo jumps up a little and status bar appears again. This happens before main method even starts.
How can I setup this so that status bar looks exactly the same from the start, until home page is shown?
EDIT:
I prepared source code: https://github.com/szotp/splash_status_problem
The jump up does not appear in completely now project for some reason, but this semi transparent background can be seen.
#szotp, i had similar issue when i tried to implement splash screen so i used flutter_native_splash package instead. It auto-generates native code for splash screens, all you need to do is provide image and color. It will merge your status bar with same color as your screen background color. Not sure what yours look like but it worked really well for me.
For few last days I'm trying to set background image in my android application. First I added my image to res/drawable-hdpi and set it as a background in .xml code of my activity by writing
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bground"
tools:context="patrycja.MainActivity" >
It didn't work so I tried also to put this image into another drawable folder in res - without success. Then I even changed the extension of my file from .jpg to .png - nothing.
So I got into res/values/styles.xml and added this:
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:background">#drawable/bground</item>
</style>
Everytime my application compiles but when I try to start it I can't even go to my first activity because it stops. LogCat shows me RuntimeException, InvocationTargetException and OutOfMemoryError. Problem must be here because my app works good with setting colour as a background.
Has anybody got an idea how to fix it?
Try this:
Use a .JPEG background.
Keep it in res/drawable-nodpi directory.
I think this will work as I have faced a similar crash earlier.
I have a strange problem with android resources. I have app created on Android 2.2 (android:minSdkVersion="8"). The application works fine.
When I installed app on for example Android 4.0, the application works fine, however at first run some resources are changed.
For example, I have drawable color named primary_color which refers to #FFFFFF html color. After installation, the system renders black color instead of white. In some cases #android:color/white renders black color.
Force closing app and restart app solving this problem.
Please help me to solve this issue.
This is caused by a bug in Android versions 4.0 to 4.1.3, I have been testing a similar problem with drawables turning to black only on devices with these versions, it is not present in devices with android version > 4.2.
I'm sure you noticed in your own research but it does not seem to be documented properly and there is no official solution but I can provide a few workarounds:
1) Turn off hardware acceleration, I used a different solution for my problem but this has been known to resolve some issues with images in the above mentioned Android versions. If you want hardware acceleration on for your application you can disable it for the problem activity by adding this to the activity declaration in your manifest.
<activity
android:name="activityName"
android:hardwareAccelerated="false"/>
2) For a solution specific to your example try setting the color to #android:color/transparent, this resolved my issue where I needed a background drawable to remain white.
3) Refer here: http://code.google.com/p/android/issues/detail?id=34619 to see a similar, documented bug and some of those solutions may work for your issue as well.
HTH
I came across the exact same problem!
I had this on colors.xml
<resources>
<color name="white">#ffffffff</color>
</resources>
And on styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#color/white</item>
</style>
The problem was that when using fragment(which contains a ListView) inside an activity the ListView shows white color as background(which is what I need) at first run but at second run the ListView background was black. The problem only existed on Android 4.0(I did not test on 4.1) but worked fine on Android 4.3, 4.4, 5 etc.
Turns out only white color had the problem, when colors other than white was used there was no black background issue!
So as I wanted a white background and I did not want to have overdraw of having multiple background so setting white as the windowBackground on styles.xml was important but at the same time it causes black background issues!
So as solution, I created another color which is not completely white but its white
<resources>
<color name="fakewhite">#fffefefe</color>
</resources>
And on styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#color/fakewhite</item>
</style>
Hence, in short color #ffffffff gets converted to #00000000 for Views like ListView and I also notice this behaviour on ScrollView.
This may not be a perfect solution but it worked for me!