消除Android程序启动时的黑屏界面
使用 Qt 开发的 Android 程序在启动时会出现短暂的黑屏,如下图,修改应用程序的主题能够解决这个问题。
在项目路径 “./android/res/values” 目录下添加一个新文件 “styles.xml”,在文件中写入下面的内容。
<?xml version='1.0' encoding='utf-8'?>
<resources>
...
<style name="MyAppTheme">
<item name="android:windowDisablePreview">true</item>
<item name="android:windowBackground">@null</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowAnimationStyle">@null</item>
<!--
<item name="android:windowBackground">@drawable/splash</item>
-->
</style>
...
</resources>
上面那段代码的功能是新建一个“MyAppTheme”主题,其中最主要的一段话是“windowDisablePreview”,目的是达到禁用应用程序Preview页的功能。
用XML编辑器打开 “AndroidManifest.xml”,在 “application” 节点上添加 android:theme="@style/MyAppTheme"
,然后保存文件。
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="-- %%INSERT_APP_NAME%% --" android:icon="@drawable/icon" android:theme="@style/MyAppTheme">
重新编译运行应用程序,就会发现启动程序之前的黑屏界面消失。