【目的】
スプラッシュ画面を作り、アプリ起動時にロゴが出るようにしたい。
【方法】
manifestに記載する方法というものが簡易でできるという話が書きURLにあったので真似てみました。
https://qiita.com/yamikoo@github/items/c82ea335968709a9d32a
【コード】
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.user1.splashtest"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:theme="@style/SplashTheme" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
styles.xml
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> <style name="SplashTheme" parent="AppTheme"> <item name="android:windowBackground">@drawable/splash</item> </style> </resources>
splash.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque" android:layout_width="match_parent" android:layout_height="match_parent"> <item android:drawable="@color/colorPrimaryDark"/> <item> <bitmap android:gravity="center" android:src="@mipmap/leon" /> </item> </layer-list>
MainActivity.kt
package com.example.user1.splashtest import android.support.v7.app.AppCompatActivity import android.os.Bundle class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // ここで1秒間スリープし、スプラッシュを表示させたままにする。 try { Thread.sleep(1000) } catch (e: InterruptedException) { } // スプラッシュthemeを通常themeに変更する setTheme(R.style.AppTheme) setContentView(R.layout.activity_main) } }
【現状】
アプリ起動時に1秒間のスリープはある模様ですが、その間に作成したスプラッシュ画面が表示されないです。また、スリープの部分のコードをなくすと、MainActivityに画像が表示される状態です。
よろしければアドバイスいただけませんでしょうか。
よろしくお願いいたします!

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/13 00:15
2018/10/13 00:17