简体   繁体   English

Flutter Android 开机画面一直黑

[英]Flutter Android Splash Screen always black

Oddly enough my android apps splash screen is white on my android emulator but black on my personal phone when I load the APK on it.奇怪的是,我的 android 应用启动画面在我的 android 模拟器上是白色的,但在我的个人手机上加载 APK 时是黑色的。

When I went to investigate I see this in the Android manifest:当我去调查时,我在 Android 清单中看到了这个:

    <meta-data
        android:name="io.flutter.embedding.android.NormalTheme"
        android:resource="@style/NormalTheme"
    />

And when I go to res drawable I see a file called launch_background.xml which sounds promising.当我 go 到 res drawable 时,我看到一个名为launch_background.xml的文件,这听起来很有希望。

But when I look inside it, it shows:但是当我看里面的时候,它显示:

<?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/launch_image" />
    </item> -->
</layer-list>

Which is odd because it says its white.这很奇怪,因为它说它是白色的。 So I am not sure what I am missing on why my cell phone boots it black.所以我不确定为什么我的手机会启动黑色。 I want to make the splash screen background color white for everyone.我想让每个人的启动画面背景颜色为白色。

If your Emulator shows a white screen and your phone shows dark maybe it's because of the dark theme on your mobile phone如果您的模拟器显示白屏而您的手机显示黑屏,可能是因为您手机的深色主题

in your phone settings change the dark mode to Light mode在您的手机设置中将暗模式更改为亮模式

settings -> display -> Lightmode

if your phone has a dark theme all the white colors will appear as black hope it helps如果你的手机有一个深色主题,所有白色 colors 都会显示为黑色希望它有帮助

create a new file named color.xml in values in given route => your_project_name\android\app\src\main\res\values and add this code.在 values in given route => your_project_name\android\app\src\main\res\values 中创建一个名为 color.xml 的新文件并添加此代码。

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

after that use this line in both drwables under layer-list tag之后在 layer-list 标签下的两个 drwables 中使用这一行

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

this will solve your issue这将解决您的问题

maybe you can add a white image;也许你可以添加一个白色图像;

Android/App/res/drawable/ white.png Android/App/res/drawable/ white.png

<?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" />

    
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/white" />
    </item>
</layer-list>

Are you using a dark theme on your phone?您在手机上使用深色主题吗? Like, do your Messenger app, email app etc have a dark background?例如,您的 Messenger 应用程序、email 应用程序等是否有深色背景?

And if so, if you change that to a light theme, does that give your splash screen a white background?如果是这样,如果您将其更改为浅色主题,是否会给您的启动画面一个白色背景?

(I was thinking since your Android manifest talks about "normal theme"... That's gotta be the overall theme of the phone, right? Perhaps remove that from the manifest?) (我在想,因为你的 Android 清单谈到“正常主题”......那一定是手机的整体主题,对吧?也许从清单中删除它?)

Also, if you follow this method to set your splash screen, including background color, does it help?:另外,如果您按照此方法设置启动画面,包括背景颜色,是否有帮助?:

https://youtu.be/JVpFNfnuOZM https://youtu.be/JVpFNfnuOZM

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

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