如何使用QML创建闪屏 [英] How to create a splash screen using QML
本文介绍了如何使用QML创建闪屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Qt开发一个Android应用程序。 我想在应用程序开始时显示一个闪屏。闪屏将停留在那里2秒钟,然后应用程序的主页面将显示。 为此,我创建了2个.qml文件。
Splash.qml
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Window 2.3
Window {
id: window
visible: true
width: Screen.width
height: Screen.height
signal timeout
Image {
id: image
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
width: 300
height: 300
source: "qrc:/../Desktop/photo_2018-03-21_19-53-06.jpg"
}
Text {
id: text1
y: image.height + image.y + 20
text: qsTr("@startimeahmet Presents")
anchors.horizontalCenter: parent.horizontalCenter
font.pixelSize: 25
}
Timer {
interval: 2000; running: true; repeat: false
onTriggered: {
visible = false
window.timeout()
}
}
}
main.qml
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Window 2.3
ApplicationWindow {
id: root
visible: false
width: Screen.width
height: Screen.height
Splash {
onTimeout: root.visible = true
}
}
但这不起作用。如有任何帮助,我们将不胜感激。
附注:我正在使用Qt 5.11.1和Qt Creator 4.6.2
推荐答案
使用本机安卓闪屏。
- 在
android/res/drawable/splash.xml
中创建启动资源。类似于
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque"> <item> <shape android:shape="rectangle" > <solid android:color="#ffffff"/> </shape> </item> <item> <bitmap android:gravity="center" android:src="@drawable/app"/> </item> </layer-list>
- 在
android/res/values/apptheme.xml
中创建主题:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="AppTheme" parent="@android:style/Theme.DeviceDefault.NoActionBar"> <item name="android:background">@drawable/splash</item> <item name="android:statusBarColor">#ffffff</item> </style> </resources>
在android/androidManifest.xml中找到
activity
元素并添加以下属性:android:theme="@style/AppTheme"
添加这些:<meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/splash"/> <meta-data android:name="android.app.splash_screen_sticky" android:value="true"/>
在您的.pro文件中添加
qt+=雄蕊
在您的C++代码中,当您的应用程序准备好时添加该行:
QtAndroid::hideSplashScreen(250);
享受!
这篇关于如何使用QML创建闪屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文