LoginSignup
4
2

More than 5 years have passed since last update.

Androidのスプラッシュスクリーンの背景色を指定する

Posted at

地味にハマったのでメモ。モバイル開発始めたばかりでとてもつらい。

まず、Xamarin公式を参考にスプラッシュスクリーンを作成する。

すると、↓こんなテーマをつくることになり、うまいこと黒背景にスプラッシュ画像が浮かび上がるようになる。

Styles.xml
<resources>
  <style name="Theme.Splash" parent="android:Theme">
    <item name="android:windowBackground">@drawable/splash</item>
    <item name="android:windowNoTitle">true</item>
  </style>
</resources>

背景色を指定できるようにする

こちら を参考に、drawableにlayer-listってのを定義する。

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

  <item>
    <shape android:shape="rectangle" >
      <solid android:color="#FFFFFFFF" />
    </shape>
  </item>
  <item>
    <bitmap
        android:gravity="center"
        android:src="@drawable/splash_image" >
    </bitmap>
  </item>

</layer-list>

splash_imageは、表示させたい画像のファイル名です。

スプラッシュ用のテーマ自体は変更なし。
windowBackgroundの先が、画像からxmlに変わっているだけ。

Styles.xml
<resources>
  <style name="Theme.Splash" parent="android:Theme">
    <item name="android:windowBackground">@drawable/splash</item>
    <item name="android:windowNoTitle">true</item>
  </style>
</resources>

以上です。
Theme.Splash内を色々いじったりしてもダメで、ハマってしまったので共有。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2