Flutter 安卓添加启动图 设置无效

1.问题

参照网上的教程 按照launch_background.xml 里注释的格式修改了<item>的内容之后
发现启动页设置无效

在这里插入图片描述

<item android:drawable="@mipmap/splash"></item>

解决

成功的实现方案是使用下面一种设置方式

在这里插入图片描述
注:将splash.png放入mipmap文件夹中 也可以使用同一分辨率的图片

AndroidManifest.xml 文件配置参考

在这里插入图片描述

            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                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>
app/main/values/styles.xml 文件配置参考

在这里插入图片描述

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
        <!-- Show a splash screen on the activity. Automatically removed when
             Flutter draws its first frame -->
        <item name="android:windowBackground">@drawable/launch_background</item>
    </style>
</resources>
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,让我来回答你的问题。 对于获取Android照片地址,可以使用flutter中的image_picker插件来实现。首先在pubspec.yaml文件中添加依赖: ``` dependencies: image_picker: ^0.6.7+22 ``` 然后在需要获取照片的位置调用以下代码即可: ```dart import 'package:image_picker/image_picker.dart'; final picker = ImagePicker(); final pickedFile = await picker.getImage(source: ImageSource.gallery); if (pickedFile != null) { final String path = pickedFile.path; // do something with the image path } ``` 对于Flutter项目安卓配置启动片,可以在Android的项目目录下的`android/app/src/main/res`文件夹中放置启动片。具体命名规则和尺寸可以参考Flutter官方文档:https://flutter.dev/docs/development/ui/advanced/splash-screen。在Android的`AndroidManifest.xml`文件中添加以下代码即可: ```xml <application android:name="io.flutter.app.FlutterApplication" android:icon="@mipmap/ic_launcher" android:label="your_app_name" android:theme="@style/LaunchTheme"> <activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/Theme.AppCompat.Light.NoActionBar" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize"> <meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable" android:resource="@drawable/launch_background" /> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> ``` 其中`@drawable/launch_background`指的是启动片的名称。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值