카테고리 없음

코틀린 해상도별 이미지 추출 / 스플래시

haniru 2024. 11. 12. 22:42

.png 파일을 아무 생각없이 폴더에 넣었는데 이런 에러가 뜬다.

이미지 하나로 해상도별 이미지 추출하는 사이트로 이미지를 해상도 별로 추출해서 이미지 넣어주면 되는 것 같다. (임시로)

https://romannurik.github.io/AndroidAssetStudio/nine-patches.html#&sourceDensity=320&name=example

 

Android Asset Studio - Simple nine-patch generator

Drag or select a source graphic to get started.

romannurik.github.io

 

그리고 스플래시 화면이라는게 생겨서 적용하는 법도 정리해본다.


기존같았으면 IntroActivity 같은 곳에 Handler 사용해서 화면을 이동했을텐데 스플래시 스크린을 사용하면 이렇게 안해도 된다.

 

https://developer.android.com/develop/ui/views/launch/splash-screen?hl=ko

 

스플래시 화면  |  Views  |  Android Developers

이 페이지는 Cloud Translation API를 통해 번역되었습니다. 스플래시 화면 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. 중요: Android 11 이하에서 맞춤 스플래시

developer.android.com

 

 

먼저 스플래시 화면을 적용하려면 프로젝트경로 /app/src/main/res/values/themes.xml 로 가서 다음처럼 입력해준다.

<style name="Theme.패키지명.Splash" ... ></style> 이쪽이 스플래시 화면을 추가해 주는 부분이다.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.패키지명" parent="android:Theme.Material.Light.NoActionBar" >
        <item name="windowNoTitle" >true</item>
    </style>
    <style name="Theme.패키지명.Splash" parent="Theme.SplashScreen">
        <item name="windowSplashScreenBackground">@color/red</item>
        <item name="windowSplashScreenAnimatedIcon">@drawable/graph</item>
        <item name="postSplashScreenTheme">@style/Theme.Bitcoin</item>
    </style>
</resources>

 

 

 

AndroidMenifest.xml

.IntroActivity 쪽에 theme.xml 에서 만들었던 스플래시 화면을 적용해줄 수 있다.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:name=".App"
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Bitcoin"
        tools:targetApi="31">
        <activity
            android:name=".IntroActivity"
            android:exported="true"
            android:theme="@style/Theme.패키지명.Splash">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.Bitcoin">
        </activity>
    </application>

</manifest>

 

 

IntroActivity.kt

installSplashScreen() 입력해줘야한다. 안 그러면 에러난다.

package com.app.bitcoin

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class IntroActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {

        installSplashScreen()

        super.onCreate(savedInstanceState)
    }
}