_flutter 安卓启动页背景图">
当前位置:   article > 正文

Flutter Android app 修改启动背景颜色和logo——筑梦之路_flutter 安卓启动页背景图

flutter 安卓启动页背景图

打开android\app\src\main\res\drawable\launch_background.xml,

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- Modify this file to customize your launch splash screen -->
  3. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  4. <!-- 自定义背景颜色-->
  5. <item android:drawable="@color/orange" />
  6. <!-- You can insert your own image assets here -->
  7. <!-- <item>
  8. <bitmap
  9. android:gravity="center"
  10. android:src="@mipmap/launch_image" />
  11. </item> -->
  12. <!-- 自定义背景图片-->
  13. <item>
  14. <bitmap
  15. android:gravity="center"
  16. android:src="@mipmap/boot" />
  17. </item>
  18. </layer-list>

准备一张图片分辨率1080 x 1920,放入android\app\src\main\res\mipmap-xxhdpi即可,图片命名为boot.png

图片对应的分辨率:

android\app\src\main\res\values下新建一个colors.xml文件

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3. <color name="orange">#FFAB40</color>
  4. <color name="transparent">#00000000</color>
  5. </resources>

找到 \app\src\main\AndroidManifest.xml 文件

  1. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  2. package="com.example.flutterapp">
  3. <!-- io.flutter.app.FlutterApplication is an android.app.Application that
  4. calls FlutterMain.startInitialization(this); in its onCreate method.
  5. In most cases you can leave this as-is, but you if you want to provide
  6. additional functionality it is fine to subclass or reimplement
  7. FlutterApplication and put your custom class here. -->
  8. <application
  9. android:name="io.flutter.app.FlutterApplication"
  10. android:label="flutterapp" <!--自定义名称-->
  11. android:icon="@mipmap/ic_launcher"> <!--自定义logo-->
  12. <activity
  13. android:name=".MainActivity"
  14. android:launchMode="singleTop"
  15. android:theme="@style/LaunchTheme"
  16. android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
  17. android:hardwareAccelerated="true"
  18. android:windowSoftInputMode="adjustResize">
  19. <!-- Specifies an Android theme to apply to this Activity as soon as
  20. the Android process has started. This theme is visible to the user
  21. while the Flutter UI initializes. After that, this theme continues
  22. to determine the Window background behind the Flutter UI. -->
  23. <!--注释这段
  24. <meta-data
  25. android:name="io.flutter.embedding.android.NormalTheme"
  26. android:resource="@style/NormalTheme"
  27. /> -->
  28. <!-- Displays an Android View that continues showing the launch screen
  29. Drawable until Flutter paints its first frame, then this splash
  30. screen fades out. A splash screen is useful to avoid any visual
  31. gap between the end of Android's launch screen and the painting of
  32. Flutter's first frame. -->
  33. <meta-data
  34. android:name="io.flutter.embedding.android.SplashScreenDrawable"
  35. android:resource="@drawable/launch_background"
  36. />
  37. <intent-filter>
  38. <action android:name="android.intent.action.MAIN"/>
  39. <category android:name="android.intent.category.LAUNCHER"/>
  40. </intent-filter>
  41. </activity>
  42. <!-- Don't delete the meta-data below.
  43. This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
  44. <meta-data
  45. android:name="flutterEmbedding"
  46. android:value="2" />
  47. </application>
  48. </manifest>

另一种方式:

  1. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  2. package="com.example.flutterxc">
  3. <!-- io.flutter.app.FlutterApplication is an android.app.Application that
  4. calls FlutterMain.startInitialization(this); in its onCreate method.
  5. In most cases you can leave this as-is, but you if you want to provide
  6. additional functionality it is fine to subclass or reimplement-->
  7. <application
  8. android:usesCleartextTraffic="true"
  9. android:name="io.flutter.app.FlutterApplication"
  10. android:label="flutterxc" //自定义app名称
  11. android:icon="@mipmap/xc_logo" //自定义app logo
  12. >
  13. <activity
  14. android:name=".MainActivity"
  15. android:launchMode="singleTop"
  16. android:theme="@style/LaunchTheme"
  17. android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
  18. android:hardwareAccelerated="true"
  19. android:windowSoftInputMode="adjustResize">
  20. // 添加这两段代码 可解决 黑屏问题(出现红线 或者 异常没关系,可以编译成功)
  21. + <meta-data
  22. + android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
  23. + android:value="true" />
  24. // 将资源指向我们的启动页路径
  25. + <meta-data
  26. + android:name="io.flutter.embedding.android.SplashScreenDrawable"
  27. + android:resource="@drawable/launch_background" />
  28. <intent-filter>
  29. <action android:name="android.intent.action.MAIN"/>
  30. <category android:name="android.intent.category.LAUNCHER"/>
  31. </intent-filter>
  32. </activity>
  33. <!-- Don't delete the meta-data below.
  34. This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
  35. <meta-data
  36. android:name="flutterEmbedding"
  37. android:value="2" />
  38. </application>
  39. </manifest>

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/549299
推荐阅读
相关标签