marsgpl commented on issue #155: URL: https://github.com/apache/cordova-plugin-statusbar/issues/155#issuecomment-1677942535
I faced the same problem and I've found the reason and the solution. Reason: cordova has default splashscreen plugin, which sets the **post-theme** of the main activity after splash screen hides: https://cordova.apache.org/docs/en/11.x/core/features/splashscreen/#androidpostsplashscreentheme the default value for that action is @style/Theme.AppCompat.NoActionBar, which provides theme with black statusbar. since hiding splashscreen takes non-zero time (especially when fade is on with non-zero duration: https://cordova.apache.org/docs/en/11.x/core/features/splashscreen/#fadesplashscreen) it leads to race condition with this plugin, when we try to do something like ```javascript document.addEventListener('deviceready', () => { navigator.splashscreen?.hide() window.StatusBar.backgroundColorByHexString('#ff0000') }, { once: true }) ``` Solution: add custom theme and provide it to AndroidPostSplashScreenTheme setting. cordova's config.xml: ```xml <widget ...> <platform name="android"> <preference name="AndroidPostSplashScreenTheme" value="@style/PostSplashScreen" /> </platform> </widget> ``` then go to **platforms/android/app/src/main/res/values/themes.xml** and add the new theme: ```xml <resources> ... other styles <style name="PostSplashScreen" parent="@style/Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">#ff0000</item> <item name="colorPrimaryDark">#ff0000</item> <item name="colorAccent">#ff0000</item> <item name="android:statusBarColor">#ff0000</item> </style> </resources> ``` https://github.com/apache/cordova-plugin-statusbar/assets/1058743/bc049ada-82fd-4762-87b4-4ebf0c6d9747 And that's it. No timeouts needed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
