apache / cordova-android

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

Splash screen branding image not showing on android 11 and below #1654

Closed baraaksayeth closed 8 months ago

baraaksayeth commented 8 months ago

Bug Report

Problem

Splash screen branding image not showing on android 11 and below

What is expected to happen?

Splash screen branding image can appear on all android versions

What does actually happen?

Splash screen branding image does not appear on android 10 and only appears on android 11 and above

Information

I used the latest api splash screen to create it, the icon and background work fine but only the branding image does not appear on android 10 and below.

How to make a branding image that supports also on android 10 and below?

Command or Code

my config.xml

...
<preference name="AndroidWindowSplashScreenAnimatedIcon" value="resources/android/splash/logo.xml" />
<preference name="AndroidWindowSplashScreenBrandingImage" value="resources/android/splash/brand_image.xml" />
<preference name="AndroidWindowSplashScreenBackground" value="#2F3992" />
...

Environment, Platform, Device

I tested on Xioami Note 8 Pro (Android 10) (didnt work) and Xioami Redmi 9 C (Android 12) (worked)

Version information

Checklist

breautek commented 8 months ago

Docs are not entirely clear but the branding image is not supported on Android 11 and earlier. It's supported only on Android 12 and later because they have native support.

The splashscreen compatibility library that backports the Splashscren API to older API levels do not support the branding image. There's an open feature request for Google to implement it in their compatibility library but several googlers have stated that the feature is a low priority.

Closing because this issue isn't actionable by Cordova. Should the feature be implemented by the compatibility library, then we can make any updates where necessary.

baraaksayeth commented 8 months ago

Thanks for the information.

after searching I found how to add a branding image on android 11 and below.

Maybe this is useful for others.

I added _launchbackground.xml in /platforms/android/app/src/main/res/drawable

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/launcherBackground" />
    <item android:gravity="center" android:drawable="@drawable/ic_cdv_splashscreen" />
    <item android:width="200dp" android:height="80dp" android:drawable="@drawable/ic_cdv_splashscreen_branding" android:gravity="center|bottom" />
</layer-list>

make sure you have a colors.xml file that located in /platforms/android/app/src/main/res/values

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

after that I changed the themes.xml which is located in /platforms/android/app/src/main/res/values

<?xml version='1.0' encoding='utf-8'?>
<resources xmlns:tools="http://schemas.android.com/tools">
    <style name="LaunchTheme" parent="Theme.SplashScreen">
        <item name="android:windowSplashScreenBrandingImage">@drawable/ic_cdv_splashscreen_branding</item>
        <item name="windowSplashScreenBackground">@color/cdv_splashscreen_background</item>
        <item name="postSplashScreenTheme">@style/Theme.AppCompat.NoActionBar</item>
        <item name="windowSplashScreenAnimationDuration">200</item>
        <item name="android:windowBackground">@drawable/launch_background</item>
        <item name="windowSplashScreenAnimatedIcon">@drawable/ic_cdv_splashscreen</item>
    </style>
</resources>

and finally I changed android:theme from AndroidManifest.xml which is in /platforms/android/app/src/main

<activity ... android:theme="@style/LaunchTheme">

I hope this will be useful for others 😄