简体   繁体   English

android 设备 flutter 中的闪屏不是全屏。 尝试了一切。 使用 flutter_native_splash

[英]Splash Screen not full screen in android device flutter. Tried everyting. Using flutter_native_splash

Flutter Splash Screen Flutter闪屏

Pubspec.YAML code- Pubspec.YAML 代码-

flutter_native_splash: ^2.0.1+1

flutter_native_splash:
  image: assets/images/splashScreen.png
  color: "#c988be"

Styles.xml - Styles.xml -

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>
    <item name="android:windowFullscreen">true</item>
</style>

if you want to hide the action bar you need to go to app manifests and then set the theme of the splash screen layout to no action bar as so:如果要隐藏操作栏,则需要转到应用程序清单,然后将启动屏幕布局的主题设置为无操作栏,如下所示:

android:theme="@style/Theme.AppCompat.NoActionBar"

if you want also to hide the status bar you use flags in the splash screen activity as so:如果您还想隐藏状态栏,您可以在初始屏幕活动中使用标志,如下所示:

@Suppress("DEPRECATION")
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        window.insetsController?.hide(WindowInsets.Type.statusBars())
    }else{
        window.setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN
        )
    }

You have to check this package flutter_native_splash , in this package you just need to set your splash screen image path.你必须检查这个包flutter_native_splash ,在这个包中你只需要设置你的启动画面图像路径。

Add this code into your pubspec.yaml file将此代码添加到您的 pubspec.yaml 文件中

flutter_native_splash:
  background_image: "assets/images/splash_bg.png"

Make sure to run this command:确保运行此命令:

flutter pub run flutter_native_splash:create

Unfortunately Android does not have good support for filling the screen without distorting the image.不幸的是,Android 没有很好的支持在不扭曲图像的情况下填充屏幕。 One way you can fix this problem is to make the splash screen larger than it needs to be, and then the splash image will be clipped by the size of the screen.解决此问题的一种方法是使启动画面大于所需的大小,然后启动画面将被屏幕大小裁剪。

When you config flutter_native_splash like this:当你像这样配置 flutter_native_splash 时:
在此处输入图像描述

After run command: "flutter pub run flutter_native_splash:create", flutter_native_splash package will generate some drawable files on android/ios folder like below:运行命令后:“flutter pub run flutter_native_splash:create”,flutter_native_splash package 将在 android/ios 文件夹中生成一些可绘制文件,如下所示:
在此处输入图像描述

In android, to display that image in fullscreen.在 android 中,全屏显示该图像。 open generated launch_background file and change gravity="center" to gravity="fill"打开生成的launch_background 文件并将gravity="center" 更改为gravity="fill"

在此处输入图像描述

After modify gravity, run your app again, you will see splash screen displayed as full screen.修改重力后,再次运行您的应用程序,您将看到启动屏幕显示为全屏。

在此处输入图像描述

hello Vietnamese compatriot Trung Đoan, in my case just leave the "image: assets/splash.png" is fine, add你好越南同胞Trung Đoan,就我而言,只要留下“image: assets/splash.png”就可以了,添加

<item>
  <bitmap android:gravity="center" android:src="@drawable/splash"/>
</item>

in launch_background.xml file, and do the rest as you said, thank you <3在launch_background.xml文件中,按照你说的做rest,谢谢<3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM