スプラッシュ画面挿入
- styles.xml
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowBackground">@drawable/background_splash</item> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style>
親となるテーマのActionBarの有無は用途によって変えてください。
重要なのは android:windowBackground
属性にdrawableを指定していることです。
background_splash
は次のように設定しています。
- background_splash.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque"> <item android:drawable="@color/colorPrimaryDark"/> <item android:gravity="center"> <bitmap android:gravity="center" android:src="@mipmap/ic_launcher"/> </item> <item android:gravity="bottom" android:bottom="@dimen/large_margin"> <bitmap android:gravity="center" android:src="@mipmap/ic_launcher"/> </item> </layer-list>
layer-listで作成します。
文字は追加できないのですが、Verctor画像で文字を作れば設定できます。
その場合はstyleをv21以降と以前で分ける必要があります。
起動するActivityに作成したテーマを設定します。
- AndroidManifest.xml
... <activity android:name=".SplashActivity" android:label="SplashCold" android:theme="@style/SplashTheme"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> ...
Splash専用のActivityを追加しなくても、スプラッシュが追加できています!