Qt/QML android 应用程序启动时如何立即显示启动画面?

How to display the splash screen immediately when Qt/QML android app is launched?

我有空 Qt/QML android 应用程序,我正在尝试显示启动画面。

没有启动画面实现显示以下画面:

现在我正在关注启动画面的 this 示例,它在 android 清单 文件中添加了 启动画面。这是我得到的结果:

我的问题是,是否可以避免 1 号屏幕?我希望启动应用程序时立即显示启动画面,而不是屏幕 1。欢迎任何建议。提前致谢。

在 Qt5.15 中,您可以 select 在 AndroidManifest.xml(在 QtCreator 中)

中 Android 本机闪屏图像

其他选择是使用简单快速的方式启动您的软件 window:只是一个 window、一个图像(异步)、一个计时器和一个用于软件其余部分的加载程序。

定时器启动后(1-2秒内),即可启动加载器。

多亏了这个post,我想我找到了这个问题的解决方案。

post 的作者,对于 Qt/QML android 应用程序中的启动画面写道:

Basically, you could ignore any solution by C++/QML code only. Because they are started late.

我想补充一点,当作者说 “他们开始晚了”,我认为这是因为你所有的 Qt/QML android app.so(共享库)一样在最后编译。所以当你的应用程序启动时,后面发生的是:

  1. 启动应用程序
  2. 正在加载 共享库(您的 Qt/QML android 应用程序)
  3. 从您的应用(共享库)调用 main()

现在显示启动画面的解决方案(步骤来自上面的post):

  1. 从 QtCreator 为您的 android 应用程序创建模板(如果您尚未创建)。

  2. android/res/drawable内创建splash.xml,如this

  3. 创建自定义主题,apptheme.xml inside android/res/values,like this

  4. activity 标签中添加这一行 in AndroidManifest.xmnl

    android:主题="@style/AppTheme"

  5. 还有AndroidManifest.xml中的这一行,在activity标签内:

    <meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/splash"/>
    
  6. 现在剩下的都在你的 main.qml 文件中。将您的 Window/ApplicationWindow 元素设置为在开始时不可见(因为我看到这将保留启动画面),将 Loader 用于您的第一页,并在其加载时设置 Window/ApplicationWIndow可见为真。这是我的例子:

Loader
{
    id: loader
    asynchronous: true
    anchors.fill: parent
    sourceComponent: MainScreen
    {
        width: root.width
        height: root.height

        Component.onCompleted:
        {
            root.isReady = true
        }
    }
}