求助:如何去除Flutter启动页Logo周围的白色背景
解决Flutter Android启动页Logo周围白色背景问题
针对你遇到的启动页Logo周围出现白色背景的问题,可尝试以下几种解决方案:
1. 确认Logo资源的有效性
- 确保Logo是带透明通道的PNG格式(JPG不支持透明,会自动填充白色背景)。
- 将Logo放入对应分辨率的资源文件夹(如
drawable-xxxhdpi),避免低分辨率图片拉伸后出现异常。 - 在Android Studio中预览Logo图片,确认资源本身无白色背景。
2. 检查启动页主题配置
打开android/app/src/main/res/values/styles.xml,确认启动页主题正确引用了修改后的launch_background:
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar"> <item name="android:windowBackground">@drawable/launch_background</item> <item name="android:windowFullscreen">true</item> </style>
若你的项目适配Android 12及以上版本,需改用新的SplashScreen API:
在values-v31/styles.xml中配置主题:
<style name="LaunchTheme" parent="Theme.SplashScreen"> <item name="android:windowSplashScreenBackground">@color/back_color</item> <item name="android:windowSplashScreenAnimatedIcon">@drawable/logo</item> <item name="postSplashScreenTheme">@style/AppTheme</item> </style>
同时在MainActivity.kt中添加适配代码:
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen class MainActivity : FlutterActivity() { override fun onCreate(savedInstanceState: Bundle?) { installSplashScreen() super.onCreate(savedInstanceState) } }
3. 优化layer-list的Bitmap配置
修改launch_background.xml,为Bitmap标签添加android:filter="false",避免图片缩放时产生伪色白边:
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/back_color"/> <item> <bitmap android:gravity="center" android:src="@drawable/logo" android:filter="false"/> </item> </layer-list>
4. 清理重建项目
- 执行终端命令:
flutter clean - 在Android Studio中依次点击
Build > Clean Project和Build > Rebuild Project - 卸载设备上的旧应用后重新安装运行
内容的提问来源于stack exchange,提问作者Okashi
相关产品推荐
相关产品推荐

