Android修炼之道——设置状态栏颜色

1.设置主题

<style name="Theme.Timetodo" parent="@android:style/Theme.Holo.Light"><!-- translucent system bars --><itemname="android:windowTranslucentStatus">true</item><itemname="android:windowTranslucentNavigation">true</item></style>

//添加了这两个属性之后 就是是这个效果了   listview顶部会与actionbar重叠,网上都是通过layout设置padding来解决

2.设置颜色和设置padding

privatevoid initSystemBar() {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(true); SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); tintManager.setStatusBarTintResource(R.color.actionbar_bg); SystemBarConfig config = tintManager.getConfig(); listViewDrawer.setPadding(0, config.getPixelInsetTop(true),0, config.getPixelInsetBottom()); }}

只不过,这个只有4.4以上是支持的

statusbar源码在frameworks/base/services/java/com/android/server/status 和 /frameworks/base/core/res/res/layout

Github 上的 SystemBarTint:Apply background tinting to the Android system UI when using KitKat translucent modes

https://github.com/jgilfelt/SystemBarTint


参考资料:

http://mindofaandroiddev.wordpress.com/2013/12/28/making-the-status-bar-and-navigation-bar-transparent-with-a-listview-on-android-4-4-kitkat/

http://stackoverflow.com/questions/20781014/translucent-system-bars-and-content-margin-in-kitkat

你可能感兴趣的:(Android修炼之道——设置状态栏颜色)