翻譯自 Boy Wang@medium
ref: Android Drawable很多android app都會使用splash screen,如下:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SplashScreenActivity">
<android.support.v7.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="40dp"
android:scaleType="centerInside"
android:layout_gravity="center"
app:srcCompat="@drawable/img_splash_screen"/>
</FrameLayout>
通常在splash screen會顯示只有一個image的layout,這樣沒問題嗎?
是的,除了在顯示splash screen前會短暫地顯示一個全白畫面。"短暫地"是多長的時間取決於你的android硬體設備。WHY?
根據以下影片Cyril Mottier關於view hierarchy的演講,得知window theme的畫面顯示優先權高於你的layout。
那要如何讓白畫面消失?幸運地,android 提供了Drawable和android:windowBackground屬性。
解決辦法:
1.Turn the splash screen to a Drawable.
![]() |
| drawable/img_splash_screen_for_window_theme.xml |
2.Add android:windowBackground in your values/styles.xml.
![]() |
| values/styles.xml |
3.Add android:windowBackground in your values/styles.xml.



沒有留言:
張貼留言