转-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>
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories