Android進階----------沉浸式標題欄實現的學習
阿新 • • 發佈:2018-12-15
1. 需注意只有5.0以上適用,以下需要適配處理,否則程式會崩掉。
一、values-v19/styles.xml 無效果,僅防止低版本崩掉
<resources> <!--values-v19。v19 開始有 android:windowTranslucentStatus 這個屬性--> <style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">true</item> </style> </resources>
二、values-v21/styles.xml
<resources> <!--values-v21 5.0 以上提供了 setStatusBarColor() 方法設定狀態列顏色。--> <style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowTranslucentStatus">false</item> <item name="android:windowTranslucentNavigation">true</item> <!--Android 5.x開始需要把顏色設定透明,否則導航欄會呈現系統預設的淺灰色--> <item name="android:statusBarColor">@android:color/transparent</item> </style> </resources>
使用:只需給activity設定主題
android:theme="@style/TranslucentTheme"
[1]本文由張風捷特烈原創,轉載