简体   繁体   English

在 Flutter 中以编程方式更改启动画面颜色

[英]Change Splash Screen Color Programmatically in Flutter

launch_background.xml 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>我如何在这里发送原色值 --> <color name="orange">#FF9800</color>

Also what should I do for IOS?另外我应该为IOS做什么?

据我所知,您不能以编程方式更改 XML 文件的值。

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在您的:app/android/src/main/res/values 中,添加一个 xml 文件 colors.xml,如下所示: colors.xml 文件
  • edit this file : app/android/src/main/res/drawable/launch_background.xml , like this : launch_background.xml file编辑这个文件: app/android/src/main/res/drawable/launch_background.xml ,像这样: launch_background.xml 文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM