您的位置:首页 > 移动开发 > Android开发

转-android沉浸式状态栏:Translucent System Bar 的最佳实践

2016-06-22 11:00 495 查看

转自简书Translucent System Bar 的最佳实践

安卓从4.4以后加入了状态栏可改变颜色的特性,通常都成为沉浸式状态栏。简单的说就是让状态栏不再是单调的黑色,实在太丑了,就像苹果那样状态栏与app是一体的。这样看上去友好很多吧。

以下是我学习作者的教程后自己的实践:

1.设置application的theme,同时要针 对各个android版本进行匹配

2.同时需要在每个布局文件的根布局加属性 android:fitsSystemWindows=”true”,根布局的背景颜色也要设置为状态栏一致的颜色android:background=”@color/top_bar_bg”

第二个步骤不设置在4.4版本中状态栏是白色的

下面会给出不同api版本的style样式

分别在res目录下新建value-19,value-21,value-23文件夹,并创建style.xml文件,当然默认的value下也要有普通的style文件

1.v19 android4.4

<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>


2.v21 android 5.0

<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">true</item>
<!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色-->
<item name="android:statusBarColor">@color/top_bar_bg</item>
</style>


3.v23 android 6.0

<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色-->
<item name="android:statusBarColor">@color/top_bar_bg</item>
</style>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 布局