iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 24
0
自我挑戰組

30 天開發 Android App 的流水帳系列 第 24

Day 24:App Splash 動畫

在等待審核的過程中,看了一下自己原先列出想要寫的內容。那就來做做開啟 App 時的動畫吧。

做法有很多種,大家在 Google 搜尋的時候,可以看看有什麼符合自己情境。以下想要實做的內容就是以在 style 新增一個 splash 的方式進行,不需多建立一個 activity 處理。

Drawable 資料夾下建立的 splash 用的 drawable

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />
    <item
        android:drawable="@mipmap/ic_launcher_round"
        android:gravity="center" />
</layer-list>

在 style 建立一個 splash 的 theme

<style name="SplashTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:windowBackground">@drawable/ic_launcher</item>
</style>

在 AndroidMainfest.xml 將 style 改成剛剛新的 SplashTheme

<application
    android:allowBackup="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/SplashTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

將進入點的 MainActivity 更新原本使用的 AppTheme style

override fun onCreate(savedInstanceState: Bundle?) {
    setTheme(R.style.AppTheme)
    super.onCreate(savedInstanceState)
}

成果

git 動畫存放處:https://drive.google.com/file/d/1phtMWNp5M6l9hsIYLtQxjvrPEIlI3qZ7/view?usp=sharing


上一篇
Day 23:Google Play Android App 送審
下一篇
Day 25:回頭檢視 Unit Test(1/2)
系列文
30 天開發 Android App 的流水帳32
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言