【问题标题】:Flutter change splash screen background colorFlutter 改变闪屏背景颜色
【发布时间】:2019-10-28 05:44:16
【问题描述】:

我的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="@android:color/white" />

    <!-- You can insert your own image assets here -->
    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/ic_launcher" />
    </item>
</layer-list>

我只是想知道,如何将 &lt;item android:drawable="@android:color/white" /&gt; 更改为自定义颜色,例如 &lt;item android:drawable="@android:color/#FFF8DC" /&gt;

【问题讨论】:

  • 在使用 Flutter 时,您是否想在 android 端进行此操作?您可以将应用程序的入口点设置为 SplashWidget,它处理您的所有身份验证/加载逻辑,然后利用 FLutter 易于使用的主题方案
  • @android:color/white 只是一个参考。您是否尝试用例如替换整个字符串? #000000?
  • @AlanNegrete 当 Flutter 应用程序启动时,launch_background.xml 中指定的背景会在 Flutter 框架初始化时在屏幕上呈现一段不确定的时间。更改此设置可让您更好地将应用品牌应用到 Android 上的发布体验中。
  • @ChanceSnow 明白了!我想它对我来说总是加载得如此之快,以至于我什至没有注意到它!

标签: android flutter


【解决方案1】:

创建文件android/app/src/main/res/values/colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <color name="red">#FF0000</color>
</resources>

编辑android/app/src/main/res/drawable/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/red" />

    <!-- You can insert your own image assets here -->
    <!-- <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/launch_image" />
    </item> -->
</layer-list>

【讨论】:

  • 它是怎么知道的?那里没有进口。请赐教
  • 因为约定俗成。
  • 啊哈,你的老板
  • 谢谢。它非常有效。我遇到了一个问题,因为使用了 android:drawable="@android: color/white" 而不是 android:drawable="@color/red"。可能对某人有用。
  • 请记住,您还需要更改 drawable-v21。 而不是
【解决方案2】:

在您的app/src/main/res/values 文件夹中创建colors.xml 文件并在该文件中写入

<color name="yourColor">#FFF8DC </color>

然后在你的launch_background.xml 文件中使用它,

<item android:drawable="@color/yourColor" />

【讨论】:

  • 这不起作用。我收到此错误android\app\src\main\res\values\colors.xml:1:50: Error: Premature end of file.。我必须删除 colors.xml 文件才能让它消失(取消注释文件中的所有内容都没有帮助)
  • 可以分享一下截图吗?我不知道你是怎么做到的
  • 您收到错误的原因是它不是颜色的完整代码。它需要格式化为 xml 。使用之前的代码sn -p
  • #C2002F
猜你喜欢
  • 2019-01-27
  • 1970-01-01
  • 2021-11-10
  • 2012-04-02
  • 1970-01-01
  • 1970-01-01
  • 2020-04-30
相关资源
最近更新 更多