文件drawable/launch_background.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowFullscreen">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowSplashScreenAnimatedIcon" tools:targetApi="s">@drawable/launch_background</item>
<!-- <item name="android:windowBackground">@drawable/launch_background</item>-->
<!-- <item name="android:windowBackground">@drawable/launch_background</item>-->
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
文件drawable-v21/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/brand_512" />-->
<!-- </item>-->
<item android:drawable="@mipmap/brand_512"></item>
</layer-list>
文件values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowFullscreen">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowSplashScreenAnimatedIcon" tools:targetApi="s">@drawable/launch_background</item>
<!-- <item name="android:windowBackground">@drawable/launch_background</item>-->
<!-- <item name="android:windowBackground">@drawable/launch_background</item>-->
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
文件values-night/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowFullscreen">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowSplashScreenAnimatedIcon" tools:targetApi="s">@drawable/launch_background</item>
<!-- <item name="android:windowBackground">@drawable/launch_background</item>-->
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
文件AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.day3"
xmlns:tools="http://schemas.android.com/tools">
<application
android:label="钱袋子"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
tools:replace="android:icon">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"/>
/>
<!-- android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"-->
<!-- android:value="true"-->
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
我的图片资源
ic_launcher.png是我的应用图标
brand_512.png是我的启动页面
现在出现的问题是启动页面不会全屏显示只显示一小块效果是
这些都替换下在清除缓存试试,这些表示不同分辨率的手机
该回答引用ChatGPT
在 Flutter 中设置启动图标和启动页面有几种不同的方式,如果你修改了 ic_launcher.png
但是没有生效,可能有以下几个原因:
pubspec.yaml
文件中的配置是否正确:在 Flutter 项目中,需要在 pubspec.yaml
文件中指定应用程序的图标和启动页,检查这些配置是否正确。flutter clean
命令,这将会清除 Flutter 项目的缓存。AndroidManifest.xml
文件中添加配置,以指定应用程序的启动图标。如果以上方法都无法解决问题,可以尝试重新创建 Flutter 项目并进行配置,或者参考 Flutter 的官方文档,了解更多关于设置启动图标和启动页面的信息。
你好,根据你提供的信息,可能是以下几个问题导致你的启动图标和启动页面无法修改生效:
缓存问题:如果你替换了启动图标和启动页面,但是没有清空缓存,那么可能会导致新的启动图标和启动页面无法生效。你可以尝试清空缓存后再运行应用程序。
图片格式问题:如果你替换的启动图标和启动页面的图片格式不正确,可能也会导致无法生效。你可以尝试使用正确格式的图片进行替换。
启动图标名称问题:如果你替换的启动图标名称不是默认的“ic_launcher.png”,可能需要在“AndroidManifest.xml”文件中进行相应的修改。
启动页面名称问题:如果你替换的启动页面名称不是默认的“LaunchActivity”,可能需要在“AndroidManifest.xml”文件中进行相应的修改。
以下是可能的解决方案:
清空缓存:在终端运行“flutter clean”命令,清空缓存后再运行应用程序。
使用正确格式的图片:确保你使用的图片格式是正确的,比如PNG格式。
修改启动图标名称:如果你的启动图标名称不是默认的“ic_launcher.png”,可以在“AndroidManifest.xml”文件的“application”标签中添加以下内容:
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/your_icon_name" />
将“your_icon_name”替换为你的启动图标名称。
<activity
android:name=".LaunchActivity"
android:exported="false"
android:label="Your App Name">
将“LaunchActivity”替换为你的启动页面名称。
希望这些解决方案可以帮助你解决问题。
你要替换掉mipmap-xxx这种格式的文件夹下的所有叫launch_image.png的图片。其次drawablev21下的也要修改。然后clean下项目,重新编译下,不行就重启下开发工具。应该没问题的。望采纳!!!
路径: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="@android:color/white" />
</layer-list>
以下答案由GPT-3.5大模型与博主波罗歌共同编写:
要修改Flutter应用程序的启动图标和启动页面,你需要进行以下步骤:
开发一个合适的图片作为启动图标,通常是一个正方形的图像。该图像的分辨率通常设置为 192x192 像素或更高。
将图标文件重命名为 ic_launcher.png,然后将该文件复制到以下目录中:<project>/android/app/src/main/res/mipmap
.
您还需要在 AndroidManifest.xml 文件中指定应用程序图标。在 AndroidManifest.xml 文件中,将以下代码块中的 ic_launcher
更改为您的图标文件名(不包括扩展名):android:icon="@mipmap/ic_launcher"
如果您想要自定义启动屏幕,请修改以下文件:<project>/android/app/src/main/res/layout/launch_background.xml
。 你可以使用任何标准的 Android 视图来构建这个启动屏幕。 例如,你可以使用一个 ImageView 控件来显示图片。
以下是一个示例代码片段,演示如何在Android中配置应用程序的启动图标和启动页面。
在 flutter 应用程序中添加图标(ic_launcher.png)。
修改 /android/app/src/main/res/mipmap/下的文件名为 ic_launcher.png。
在 AndroidManifest.xml 文件中添加如下代码:
<application
android:name="io.flutter.app.FlutterApplication"
... >
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
<activity
...
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"/>
</activity>
</application>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/splash_background"/>
</item>
<!-- You can insert your own image assets here -->
<!--<item>-->
<!--<bitmap-->
<!--android:gravity="center"-->
<!--android:src="@mipmap/ic_launcher" />-->
<!--</item>-->
</layer-list>
<resources>
<color name="splash_background">#FFFFFF</color>
</resources>
希望这些步骤对你有帮助!
如果我的回答解决了您的问题,请采纳!