AndroidでQtを使用してスプラッシュスクリーンを実装する
Android向けQtを使用したスプラッシュスクリーンの設定方法をご紹介します。

これは、Qt を使用してスプラッシュスクリーンを表示する一つの方法を示す簡単な例です。アプリが起動すると、ロゴと背景色を含む Qt のスプラッシュスクリーンが 2 秒間表示されます。その後、Qt のスプラッシュスクリーンがフェードアウトし、アプリのメインビューが表示されます。メインビューは、シンプルなラベルと閉じるボタンで構成されています。
この例では、Androidのデフォルトのスプラッシュスクリーン(Android 12以降)は非表示になっています。
この例は、スプラッシュ画面を実演する2つの類似した例のうちの1つです。この例では AndroidManifest のフラグを使用していますが、もう一方の例ではQML ビューを使用しています。
AndroidでのQtスプラッシュスクリーンの使用
Android用のQtスプラッシュ画面は、AndroidManifest.xmlで定義されます。Androidプロジェクトファイルは、手動で作成するか、Qt Creator のテンプレートジェネレータを使用して作成できます。Qt Creator のテンプレートジェネレータを使用してAndroidプロジェクトファイルを作成するには:
- [Android]Projects
- 「Build Steps 」サブセクションに移動
- 開くBuild Android APK
- 「Application 」サブセクションから「Create Templates 」を選択します
<meta-data android:name="android.app.splash_screen_drawable"
android:resource="@drawable/qtsplashscreen"/>
<meta-data android:name="android.app.splash_screen_sticky"
android:value="true"/>前のスニペットでは:
- android.app.splash_screen_drawable は、Qt スプラッシュスクリーンを定義するリソースファイルを指定します。
- android.app.splash_screen_sticky は、QNativeInterface::QAndroidApplication::hideSplashScreen() 関数が呼び出されるまで、Qt スプラッシュスクリーンを画面上に表示し続けます。
QNativeInterface::QAndroidApplication::hideSplashScreen(2000);
Android 12以降、Androidにはデフォルトのスプラッシュ画面が搭載されています。起動時、アプリケーションの最初のビューが表示される前に、このデフォルトのスプラッシュ画面が表示されます。これを変更するための手順とAPIが用意されています。詳細は「Androidのスプラッシュ画面」を参照してください。
デフォルトでは、Androidはスプラッシュ画面としてアプリケーションのアイコンを使用します。 Qtアプリケーションでは、これをそのまま使用することも、アプリケーションのスプラッシュ画面として変更することも、あるいはQtのスプラッシュ画面と組み合わせることも可能です。プラットフォーム間で起動時のユーザーエクスペリエンスを統一するために、Androidのスプラッシュ画面を非表示にする必要がある場合があります。これを行うには、Androidのスプラッシュ画面を事実上非表示にする半透明のテーマを定義します。
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="splashStartTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowDisablePreview">true</item>
<item name="android:windowIsTranslucent">true</item>
</style>
</resources>ただし、問題があります。半透明テーマを使用すると、画面の向き変更が機能しなくなります。これは、Androidのビューがその向きを基になるビューから取得するためです。通常、この基になるビューはアプリケーションドロワーであり、その向きは変化しません。 また、Activityビューが設定された後はテーマを変更できないため、アプリケーションが1つの向きに固定されたままになってしまうのです。
回避策として、Androidのスプラッシュ画面用に半透明テーマを適用した一時的なActivityを作成することができます。できるだけ早く、アプリケーションに必要なすべての機能を備えた別のActivityを起動します。
<activity
android:name=".SplashActivity"
android:exported="true"
android:theme="@style/splashStartTheme"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>Qtのスプラッシュスクリーンを起動するには、AndroidのActivityクラス(onCreate )をオーバーライドし、Intentを使用してQtActivityを起動する必要があります。
package io.qt.qtsplashscreeninandroid;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.util.Log;
import android.content.Intent;
import android.view.ViewTreeObserver;
import org.qtproject.qt.android.bindings.QtActivity;
public class SplashActivity extends Activity {
private static final String TAG = "SplashActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set up an OnPreDrawListener to the root view.
final View content = findViewById(android.R.id.content);
content.getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
Intent intent = new Intent(SplashActivity.this, QtActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
content.getViewTreeObserver().removeOnPreDrawListener(this);
finish();
return true;
}
});
}
}この例では、メインビューには終了ボタンが付いた単一のビューのみが含まれています。
import QtQuick
import QtQuick.Controls
Window {
visible: true
title: qsTr("Qt Splash Screen Example")
color: "#2CDE85"
Text {
id: textLabel
text: "First View"
anchors.centerIn: parent
}
Button {
id: closeButton
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: textLabel.bottom
anchors.topMargin: 5
background: Rectangle {
color: "#00414A"
radius: 2
}
text: "Close"
contentItem: Text {
color: "#FFFFFF"
text: closeButton.text
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
onClicked: {
Qt.callLater(Qt.quit)
}
}
}© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.