您现在的位置是:网站首页> C/C++
Qt Android解决启动界面黑屏或白屏
- C/C++
- 2023-08-25
- 781人已阅读
实例项目结构图
pro文件
QT += core gui androidextras
...
DISTFILES += \
android/AndroidManifest.xml \
android/build.gradle \
android/gradle/wrapper/gradle-wrapper.jar \
android/gradle/wrapper/gradle-wrapper.properties \
android/gradlew \
android/gradlew.bat \
android/res/values/libs.xml \
android/res/values/style.xml \
android/res/drawable/logo.png \
android/src/org/qtproject/example/Hello.java
..
main.cpp
#include "mainwindow.h"
#include <QApplication>
#include<QTimer>
#include <QtAndroidExtras/QtAndroid>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QTimer::singleShot(3000,[=](){
QtAndroid::hideSplashScreen(500);
});
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
style.xml
<?xml version='1.0' encoding='utf-8'?>
<resources>
<style name="Theme.AppStartLoad" parent="android:Theme">
<item name="android:windowBackground">@drawable/logo</item>
<!-- @drawable/logo 确保 android\res\drawable-hdpi\logo.png 存在 -->
<item name="android:windowNoTitle">true</item>
</style>
<style name="Theme.AppStartLoadTranslucent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
AndroidManifest.xml
...
<application android:theme="@style/Theme.AppStartLoadTranslucent" android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="-- %%INSERT_APP_NAME%% --">
<activity android:theme="@style/Theme.AppStartLoad" android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="unspecified" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
...