Change Splash Screen Color Programmatically in Flutter

2,583

Solution 1

You can change the color of your splash screen, just follow steps :

  • in your : app/android/src/main/res/values, add an xml file colors.xml like this :colors.xml file
  • edit this file : app/android/src/main/res/drawable/launch_background.xml , like this : launch_background.xml file

Solution 2

As far as I know, you can't change values of an XML file programmatically.

Share:
2,583
katre
Author by

katre

Updated on December 17, 2022

Comments

  • katre
    katre over 1 year

    launch_background.xml

    <?xml version="1.0" encoding="utf-8"?>
    <!-- Modify this file to customize your launch splash screen -->
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@color/orange" />
        <!-- You can insert your own image assets here -->
        <item>
            <bitmap
                android:gravity="center"
                android:src="@drawable/splash_icon" />
        </item> -->
    </layer-list>
    

    styles.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
            <!-- Show a splash screen on the activity. Automatically removed when
                 Flutter draws its first frame -->
            <item name="android:windowBackground">@drawable/launch_background</item>
        </style>
        <color name="orange">#FF9800</color>
    </resources>
    

    I change the primary color value in the app dynamically and set theme colors for app. How can I send the primary color value here --> <color name="orange">#FF9800</color>

    Also what should I do for IOS?

    • Abhijith K
      Abhijith K about 4 years
      What is the purpose of this? Do you want to see different colors in the splash screen each time you launch the app? Or is there a way the user can set the splash screen color of his choice? Can you explain in detail?
    • katre
      katre about 4 years
      There are different theme colors in my app. I want to change the splash screen background color according to the theme color.
    • Abhijith K
      Abhijith K about 4 years
      when does the theme color change, during which action?
    • katre
      katre about 4 years
      At any time while the application is running. I save the color value to shared preferences
    • C4s4r
      C4s4r almost 4 years
      Have you already found a solution for this?
    • Chetan Goyal
      Chetan Goyal almost 4 years
  • katre
    katre over 3 years
    Question: How can it be changed dynamically (Programmatically)? You don't understand the question. Review again.
  • Athos Tokbi
    Athos Tokbi about 3 years
    @Djamel I tried the way you have shared the .xml file, but the thing is that my colors.xml file is not being recognized, I have tried the restart/invalidCaches
  • Athos Tokbi
    Athos Tokbi about 3 years
    still, my file is not being recognzsed