更改导航栏颜色,Android

时间:2014-12-21 13:31:26

标签: java android xml

如何在前Lollipop设备中将导航栏的颜色/透明度从黑色更改为通用颜色(例如状态栏或操作栏的颜色)?

我可以使用AppCompat来实现,还是仅适用于SDK 21?

3 个答案:

答案 0 :(得分:10)

您可以在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或更早版本则不支持此功能。

答案 1 :(得分:4)

另一种编程方式:

<div class="pictures-page">
<div class="col-md-6"><img src="/assets/components/phpthumbof/cache/27.71c8b506d35dd3f2df6e61c93e7bb2973.jpg"></div>
<div class="col-md-6">TEXT</div>
<div class="col-md-6"><img src="/assets/components/phpthumbof/cache/27.71c8b506d35dd3f2df6e61c93e7bb2973.jpg"></div>
<div class="col-md-6">TEXT</div>
<div class="col-md-6"><img src="/assets/components/phpthumbof/cache/27.71c8b506d35dd3f2df6e61c93e7bb2973.jpg"></div>
<div class="col-md-6">TEXT</div>
<div class="col-md-6"><img src="/assets/components/phpthumbof/cache/27.71c8b506d35dd3f2df6e61c93e7bb2973.jpg"></div>
<div class="col-md-6">TEXT</div>
<div class="col-md-6"><img src="/assets/components/phpthumbof/cache/27.71c8b506d35dd3f2df6e61c93e7bb2973.jpg"></div>
<div class="col-md-6">TEXT</div>   


</div>

此外,要更改状态栏颜色,请添加以下行:

window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(R.color.DarkOrange));
window.setNavigationBarColor(getResources().getColor(R.color.red));

答案 2 :(得分:2)

式-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>