apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.59k stars 1.52k forks source link

SplashScreen Background not working #1623

Closed jDavid95 closed 5 months ago

jDavid95 commented 11 months ago

I´m trying to set a background for my splashscreen, but it´s not working, it either shows a white or black/charcoal background (which is not the one I want to use). I´m currently on Cordova-Android 11 Phone brands tested: Pixel (emulator), Xiaomi's (real), and Samsung(real)

this is how my config.xml looks like:

 <platform name="android">
        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
            <application android:networkSecurityConfig="@xml/network_security_config" />
        </edit-config>
        <resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
        <resource-file mode="merge" src="resources/android/xml/logo_background.xml" target="/app/src/main/res/values/colors.xml" />
        <allow-intent href="market:*" />
        <icon background="@color/logo_background" density="mdpi" foreground="resources/android/icon/drawable-mdpi-icon.png" />
        <icon background="@color/logo_background" density="hdpi" foreground="resources/android/icon/drawable-hdpi-icon.png" />
        <icon background="@color/logo_background" density="xhdpi" foreground="resources/android/icon/drawable-xhdpi-icon.png" />
        <icon background="@color/logo_background" density="xxhdpi" foreground="resources/android/icon/drawable-xxhdpi-icon.png" />
        <icon background="@color/logo_background" density="xxxhdpi" foreground="resources/android/icon/drawable-xxxhdpi-icon.png" />
        <preference name="AndroidWindowSplashScreenAnimatedIcon" value="resources/splash.xml" />
        <preference name="AndroidWindowSplashScreenBackground" value="#003366" />
    </platform>

I included all the platform section in case something else is messing with the background.

jDavid95 commented 11 months ago

If anybody is looking for a solution to this:

this is how I solved (with the way my config looks like):


I just needed to use a splash in PNG, and get rid of the resource file merging to the 'colors.xml'. Though I know this is not the best implementation since the values of the resource file got merged into the colors.xml, it solves the issue.

breautek commented 9 months ago

This can be caused if something is overwriting the colors.xml resource file and doesn't properly include cdv_splashscreen_background color.

I believe the ionic framework is a common example that clashes with Cordova with this.

I don't really consider this a bug but I'll attach this to a v13 milestone. Personally I think we should be namespacing our resource files to avoid clashes. But changing the resource file location may be breaking, so it may have to wait for the next major.

alitalaee commented 1 week ago

I had the same issue and could to change splash screen background color..

config.xml <preference name="AndroidWindowSplashScreenAnimatedIcon" value="resources/android/splash/drawable-port-xxxhdpi-screen.png" /> After this line i added background color change config like this

<preference name="AndroidwindowSplashScreenBackground" value="#E2AD81" /> colors.xml

<?xml version='1.0' encoding='utf-8'?>
<resources xmlns:tools="http://schemas.android.com/tools">
    <color name="cdv_splashscreen_background">#E2AD81</color>
</resources>

themes.xml `<?xml version='1.0' encoding='utf-8'?>

`

After add this config run below commands

ionic cordova prepare android

ionic cordova build android --minifycss --optimises --minifyjs --prod --release

it is working for