很多APP打開都會有啓動界面,但是全面屏問世後就會有很多問題出現。我們這裏採用更快更高效的啓動方式通過them設置,通過介紹筆者在實際項目開發中遇到的問題和解決方法,讓大家更深入瞭解them、全面屏適配、虛擬按鈕與狀態欄控制。
當然,有小夥伴非要自己去定義xml頁面作爲啓動。。。這篇文章你也可以作爲儲備技能拓展
遇到問題問下:
1、Them是什麼東西,如何設置Them可以隱藏狀態欄和虛擬按鈕?
2、全面屏如何適配(讓圖片背景鋪滿)?
3、圖片背景內容被拉伸怎麼處理?
1、Them是什麼東西,如何設置Them可以隱藏狀態欄和虛擬按鈕?
Them:主題,相當於APP皮膚,可以進行很多界面設置
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!--導航欄顏色-->
<item name="colorPrimary">@color/colorRed</item>
<!--通知欄顏色-->
<item name="colorPrimaryDark">@color/colorYellow</item>
<!--控件選中後顏色-->
<item name="colorAccent">@color/colorBlue</item>
</style>
效果圖:
隱藏狀態欄和虛擬按鈕
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!--導航欄顏色-->
<item name="colorPrimary">@color/colorPrimary</item>
<!--通知欄顏色-->
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<!--控件選中後顏色-->
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@drawable/timg</item>
<!--導航欄背景色-->
<item name="android:navigationBarColor">@color/transparent</item>
<!--狀態欄背景色-->
<item name="android:statusBarColor">@color/transparent</item>
<!-- ***********常用屬性 只是介紹,需要就選用************* -->
<!--是否顯示標題欄-->
<!-- <item name="windowNoTitle">true</item>-->
<!--全屏設置-->
<!-- <item name="android:windowFullscreen">true</item>-->
<!--進入動畫-->
<!-- <item name="android:windowEnterAnimation">@anim/bg_in</item>-->
<!--退出動畫-->
<!-- <item name="android:windowExitAnimation">@anim/bg_out</item>-->
<!--自適應窗口-->
<!-- <item name="android:fitsSystemWindows">true</item>-->
</style>
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
因爲繼承了NoActionBar,所以簡單的設置了下狀態欄、虛擬按鈕和背景圖片
未設置的效果圖 設置後的效果圖
2、全面屏適配
全面屏有時在Them設置好圖片時,會發現狀態欄是沒有填滿,有黑邊遺留,此時需要在配置文件中加入以下代碼
<!--適配全面屏-->
<meta-data
android:name="android.max_aspect"
android:value="2.4" />
3、啓動頁圖片背景內容被拉伸處理
處理方法:製作 .9 圖,只拉伸需要拉伸的區域
效果圖:
贈人玫瑰,手有餘香。如果對你有幫助,請大方給個贊!