0

I added a native launch screen for dark and light mode, so when my device in night mode the background color of the launch screen is black and when the device in light mode the color is white.

The problem is:

I want to make the color depend on the user, if user's device in night mode and he choose the light mode inside my app the background color of the launch screen must be white

more explain:

If the device in night mode and my app theme is light mode the launch screen background color should be white (depend on the application theme not on the device)

how can I achieve this from native code?

Mahmoud Haj Ali
  • 946
  • 6
  • 12
  • Did you find the correct answer? – itsji10dra Jun 13 '23 at 15:07
  • Unfortunately not. – Mahmoud Haj Ali Jun 21 '23 at 22:26
  • What I found out is that the launch screen's background color is actually picked by OS based on its theme. Since the app is actually launched after when the runApp() function in main() is called, there you override your app to show the user-chosen theme. So ideally it's not possible to override the launch screen bg color. I have verified it with the other apps in AppStore as well. They have the same issue and they live with it. You can verify the same pattern in the Facebook app from AppStore. – itsji10dra Jun 22 '23 at 06:02
  • Even if we write some code from native side? – Mahmoud Haj Ali Jun 22 '23 at 12:44
  • 1
    Even native apps won't be able to fix it. I verified that too. Atleast I am sure about iOS. A popular practise I noticed in the apps around the globe is to use a background color that can be used for both dark and light mode. Example, PayPal iOS app. – itsji10dra Jun 22 '23 at 13:18

1 Answers1

1

You can add the below tag to the root element in your native splash screen xml.

android:forceDarkAllowed="false"

This flag will ignore the System dark mode.

Now To enable/disable Night mode for a single activity you can use below code in your OnCreate method before super.onCreate method call:

getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO); // Disabled
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES); // Enabled
Alpha 1
  • 4,118
  • 2
  • 17
  • 23
  • 1
    thanks, but this will force the splash screen to be always light mode I want to change the theme between dark mode and light mode but not depending on system mode – Mahmoud Haj Ali May 23 '21 at 05:28
  • 1
    I have updated my answer. Please check it once. – Alpha 1 May 23 '21 at 05:35
  • 2
    I appreciate your edit, but in my main activity the super class is **FlutterActivity** and there is no onCreate method, so i tried to override it but it can't see the **getDelegate()** and **AppCompatDelegate** – Mahmoud Haj Ali May 23 '21 at 05:45
  • Ohh I thought it's for native. Sorry, my bad. refer this answer. It might help : https://stackoverflow.com/a/64185945/6147653 – Alpha 1 May 23 '21 at 05:47
  • 1
    Never mind, I forgot to add flutter word to the question title – Mahmoud Haj Ali May 23 '21 at 05:50
  • 1
    The answer doesn't help unfortunately, because he want to change the theme from the flutter side not from native side – Mahmoud Haj Ali May 23 '21 at 05:51