Home > Blockchain >  How to change splash screen in dark mode(Android)?
How to change splash screen in dark mode(Android)?

Time:03-15

I created a simple project and added the flutter_native_splash package. I am running this project on my android phone via USB. If my phone is in light mode splash screen works fine. But in the dark mode, it did not work. So then I tried to add my splash screen image to android/app/src/main/res/drawable-night and it worked. The problem is when I tried to build apk it gives me an error. If I remove what I added to android/app/src/main/res/drawable-night I can build apk successfully

CodePudding user response:

In your project folder's android/app/src/main/res there should be a drawable folder, which contains the launch_background.xml for light theme. Duplicate this folder and call the second one drawable-night and configure the dark theme style. It will automatically change based on Android's system theme.

The launch_background.xml in the drawable (light theme) folder can be structured as so, to display an image with a white background:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/launch_image" />
    </item>
</layer-list>

Here are some sources,Here and Source

CodePudding user response:

You can use state management with theme you want if you want light or dark, for example.

appProvider.isLight ?? Themedata.LightMode : Themedata.DarkMode;
  • Related