![](/img/trans.png)
[英]How to change the color of the navigation and status bar on Android Java?
[英]Change navigation bar color, Android
如何在前Lollipop設備中將導航欄的顏色/透明度從黑色更改為通用顏色(例如狀態欄或操作欄的顏色)?
我可以使用AppCompat來實現,還是僅適用於SDK 21?
您可以在AppCompat主題中設置屬性navigationBarColor
,或在本機v21主題中設置android:navigationBarColor
。
<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
...
<item name="navigationBarColor">#123456</item>
</style>
https://developer.android.com/training/material/theme.html#StatusBar
請注意,這不適用於Pre-Lollipop設備,因為系統需要支持此功能,而Android 4.4或更早版本則不支持此功能。
另一種編程方式:
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(R.color.DarkOrange));
window.setNavigationBarColor(getResources().getColor(R.color.red));
此外,要更改狀態欄顏色,請添加以下行:
window.setStatusBarColor(getResources().getColor(R.color.green));
風格-V21
<resources>
<style name="Theme.DesignDemo" parent="Base.Theme.DesignDemo">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentNavigation">true</item>//translucent
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
</style>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.