Android에서 Qt로 스플래시 화면 구현하기
안드로이드용 Qt로 스플래시 화면을 설정하는 방법을 보여드립니다.
이 예제는 Qt로 스플래시 화면을 표시하는 한 가지 방법을 보여주는 간단한 예제입니다. 앱이 시작되면 로고와 배경색이 있는 Qt 스플래시 화면이 2초 동안 표시됩니다. 그런 다음 Qt 시작 화면이 페이드 아웃되어 앱 메인 보기가 표시됩니다. 메인 보기는 간단한 레이블과 닫기 버튼으로 구성됩니다.
이 예에서는 안드로이드 기본 스플래시 화면(안드로이드 12 이후)이 숨겨져 있습니다.
이 예제는 스플래시 화면을 보여주는 두 가지 유사한 예제 시리즈 중 하나입니다. 이 예제는 안드로이드 매니페스트 플래그를 사용하고 다른 예제는 QML 뷰를 사용합니다.
안드로이드에서 Qt 스플래시 화면 사용하기
안드로이드용 Qt 스플래시 화면은 AndroidManifest.xml에 정의되어 있습니다. Android 프로젝트 파일은 수동으로 생성하거나 Qt Creator 템플릿 생성기를 사용하여 생성할 수 있습니다. Qt Creator 템플릿 생성기를 사용하여 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);
안드로이드 12부터 안드로이드에는 기본 스플래시 화면이 있습니다. 실행 시 애플리케이션의 첫 번째 보기가 표시되기 전에 기본 스플래시 화면이 표시됩니다. 이를 수정하기 위한 지침과 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 보기가 기본 보기에서 방향을 가져오기 때문에 발생하며, 일반적으로 방향을 변경하지 않는 애플리케이션 서랍입니다. 그리고 활동 보기가 설정된 후에는 테마를 변경할 수 없기 때문에 결국 애플리케이션이 한 방향으로 고정됩니다.
해결 방법으로 Android 스플래시 화면에 반투명 테마를 사용하여 버려지는 활동을 만들 수 있습니다. 가능한 한 빨리 애플리케이션에 필요한 모든 기능을 갖춘 다른 액티비티를 실행합니다.
<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 스플래시 화면을 시작하려면 안드로이드 액티비티 onCreate
를 재정의하고 인텐트를 사용하여 Qt 액티비티를 시작해야 합니다.
// Copyright (C) 2025 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 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; } }); } }
이 예제에서는 메인 뷰에 종료 버튼이 있는 단일 뷰만 포함되어 있습니다.
// Copyright (C) 2017 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 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) } } }
© 2025 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.