【发布时间】:2023-01-31 12:08:58
【问题描述】:
我有应用程序,我需要使用带有背景颜色和应用程序的启动画面图标在它的中心。
的问题地图,如果我在 drawable 目录中使用图像它会工作,但我需要贴图因为它有多个dhp尺寸。
有人知道这个的解决方案吗?
笔记:我知道android 32有专门的演示,我需要在所有版本中解决这个词。
谢谢你。
【问题讨论】:
标签: android flutter dart splash-screen mobile-application
我有应用程序,我需要使用带有背景颜色和应用程序的启动画面图标在它的中心。
的问题地图,如果我在 drawable 目录中使用图像它会工作,但我需要贴图因为它有多个dhp尺寸。
有人知道这个的解决方案吗?
笔记:我知道android 32有专门的演示,我需要在所有版本中解决这个词。
谢谢你。
【问题讨论】:
标签: android flutter dart splash-screen mobile-application
它可能不是最好的选择,但如果你想让它在所有版本和所有设备上工作,你可以在 flutter 中制作你自己的闪屏页面。它可以解决你的问题。
例如在你的 main.dart 文件中
runApp(MaterialApp(
theme: ThemeData(
colorScheme: ColorScheme.light().copyWith(
primary: Colors.red,
),
),
home: SplashPage(), // here is your splash screen page
));
在您的 SplashPage 文件中,您可以根据需要运行一些异步函数,然后您可以导航到主页。
【讨论】:
首先,要添加不带包的原生启动画面,您需要准备以下尺寸的应用程序图标或图像
1- mdpi = 1x pixel
2-xhdpi = 2x pixel
3-xxhdpi = 3x pixels
4- xxxhdpi = 4x pixel
5-hdpi = 1.5x pixels
as x is the size of the ixcons
然后在路径中添加所有与每个应用程序图标同名的图标,就像这个图像一样
在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/color_name" />
<!-- You can insert your own image assets here -->
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/image or app icon name" />
</item>
然后改变颜色
1-create colors file at
example_app/android/app/src/main/res/values/
2- write the color code you want
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="splash_color">#ED9728</color>
</resources>
【讨论】:
使用flutter_native_splash: ^2.2.17包生成不同平台的原生启动画面
【讨论】:
你可以在你的dev_dependencies中使用flutter_native_splash。这将使它可用作生成启动画面的命令行工具,但该程序包不会编译到您的应用程序中。如果您甚至不想将它保留在您的dev_dependencies 中,您可以运行它一次,将其从您的项目中删除,然后如果您想进行额外的手动调整,则检查哪些文件有机会。
完全披露:我维护这个包。
【讨论】: