【问题标题】:Change Splash Screen Color Programmatically in Flutter在 Flutter 中以编程方式更改启动画面颜色
【发布时间】:2020-05-23 16:35:24
【问题描述】:

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>

我动态更改应用程序中的原色值并为应用程序设置主题颜色。如何在此处发送原色值 --> &lt;color name="orange"&gt;#FF9800&lt;/color&gt;

还有IOS应该怎么做?

【问题讨论】:

  • 这样做的目的是什么?您想在每次启动应用程序时在启动画面中看到不同的颜色吗?或者有没有一种方法可以让用户设置他选择的启动画面颜色?能详细解释一下吗?
  • 我的应用中有不同的主题颜色。我想根据主题颜色改变闪屏背景颜色。
  • 主题颜色什么时候改变,在哪个动作期间?
  • 应用程序运行期间的任何时间。我将颜色值保存到共享首选项
  • 您已经找到解决方案了吗?

标签: android ios flutter splash-screen


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    您可以更改初始屏幕的颜色,只需按照以下步骤操作:

    • 在您的:app/android/src/main/res/values 中,添加一个 xml 文件 colors.xml,如下所示:colors.xml file
    • 编辑这个文件:app/android/src/main/res/drawable/launch_background.xml,像这样: launch_background.xml file

    【讨论】:

    • 问题:如何动态(以编程方式)更改?你不明白这个问题。再次审核。
    • @Djamel 我尝试了您共享.xml 文件的方式,但问题是我的colors.xml 文件未被识别,我尝试了重启/invalidCaches
    • 仍然,我的文件没有被识别
    猜你喜欢
    • 2019-03-07
    • 1970-01-01
    • 2015-07-13
    • 2011-02-04
    • 1970-01-01
    • 2015-12-06
    • 2021-03-31
    • 1970-01-01
    相关资源
    最近更新 更多