做過Splash的都知道,一般的做法是在style中設(shè)置windowBackground為啟動圖,來避免冷啟動時的黑屏,但是如果放一張尺寸的圖在某些屏幕上就會出現(xiàn)拉伸,并且windowBackground還不能centerCrop,就算通過資源限定符也不能完美的適配
1. windowBackground
首先需要解決windowBackground的拉伸問題,用一整張圖肯定不行,所以這里只需要一張slogan圖片,然后通過layer-list來實現(xiàn)。
在drawable下建一個splash.xml
? ? <!--單獨的slogan圖片 并且設(shè)置下間距-->
android:bottom="46dp"
android:drawable="@drawable/ic_slogan"
android:gravity="bottom|center">
2. Activity Theme
新建一個Splash主題,windowBackground設(shè)置成剛剛建的splash.xml
@drawable/splash_lay
true
true
@android:color/transparent
@android:color/transparent
如果有NavigationBar?手機上圖片或被遮住
在5.0后,增加了一個windowDrawsSystemBarBackgrounds屬性,用來標(biāo)志此窗口是否負(fù)責(zé)繪制系統(tǒng)欄背景,我們把它設(shè)成false,這樣當(dāng)它繪制windowBackground的時候,就會在NavigationBar之上。