Android 使用SystemBarTint设置状态栏颜色
来源:互联网 发布:淘宝手机测量尺码在哪 编辑:程序博客网 时间:2024/06/08 00:19
做项目时,发现APP的状态栏是系统默认的颜色,突然想到,为啥别的APP是自己设置的颜色(和APP本身很相搭),于是也想给自己的APP设置系统状态栏的颜色,更加美美哒。。。
搜了下,发现原来设置状态栏居然有个很高大上的名字(听不懂的都是高大上)——沉浸式状态栏,Android4.4以后开始支持沉浸式状态栏, 继续搜索,发现,有一个很简单的开源项目——SystemBarTint,可以很完美的支持沉浸式状态栏。
SystemBarTint地址: https://github.com/hexiaochun/SystemBarTint
下面,简单演示下如何使用该库,首先,先看下效果,有图才有真相:
1. 引入类库
使用Android Studio,直接在build.gradle文件中引入库:
dependencies { compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'}
使用Eclipse,可下载JAR包,并引入到项目的libs文件夹中。
2. 在Activity中添加方法:
/** * Apply KitKat specific translucency. */ private void applyKitKatTranslucency() { // KitKat translucent navigation/status bar. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(true); SystemBarTintManager mTintManager = new SystemBarTintManager(this); mTintManager.setStatusBarTintEnabled(true); mTintManager.setStatusBarTintResource(R.color.colorTop);//通知栏所需颜色 } } @TargetApi(19) private void setTranslucentStatus(boolean on) { Window win = getWindow(); WindowManager.LayoutParams winParams = win.getAttributes(); final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if (on) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } win.setAttributes(winParams); }
然后, 在OnCreate()方法中调用applyKitKatTranslucency方法:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); applyKitKatTranslucency(); }
3. 在style.xml中,添加系统的样式:
<!-- 去掉tab顶部的黑边 --> <style name="no_title" parent="@android:style/Theme.Light.NoTitleBar"> <!-- 沉浸式状态栏 --> <item name="android:fitsSystemWindows">true</item> <item name="android:clipToPadding">false</item> </style>
当然了,别忘了在AndroidManifest.xml进行配置主题:
<application android:name=".activity.base.MyApp" android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:persistent="true" android:theme="@style/no_title"></application>
注: 这个是必要的,如果不添加,会造成一些页面的变形。
综上, 便可以在4.4以上的系统中方便的设置状态栏颜色,有木有感觉你的APP变得更好看了呢!
扩展:http://www.jianshu.com/p/e1c937000343
0 0
- Android 使用SystemBarTint设置状态栏颜色
- Android 使用SystemBarTint设置状态栏颜色
- SystemBarTint的使用(设置半透明状态栏)
- SystemBarTint的使用(设置半透明状态栏)
- SystemBarTint的使用(设置半透明状态栏)
- SystemBarTint的使用(设置半透明状态栏)
- Android头部状态栏SystemBarTint
- Android使用systembartint库实现沉浸式状态栏效果
- Android 透明状态栏了解使用 及SystemBarTint 解读
- android透明状态栏与开源库SystemBarTint的使用
- Android沉浸式状态栏SystemBarTint
- Android设置状态栏颜色
- android设置状态栏颜色
- Android 设置状态栏颜色
- Android 状态栏颜色设置
- Android状态栏颜色设置(沉浸式状态栏)
- Android 状态栏透明、自定义状态栏颜色设置
- Android 设置状态栏颜色&&沉浸式状态栏
- js中console命令的使用
- 网络通信(TCP和UDP)
- 发布iOS企业分发(三)(生成ipa及下载链接)
- ClippingNode的简单使用
- solr5.3.1从mysql导入索引
- Android 使用SystemBarTint设置状态栏颜色
- 我看Java虚拟机(5)---虚拟机加载机制
- linux使用Xmanager连接CentOS 5.5
- hdu 2897 巴什博弈裸题
- week13---12月2日 JS内置对象(四)
- 12. Spring Security Remember-Me功能
- typedef和define有什么区别
- C-001.第一个C语言程序
- VS2010创建和显式调用dll