安卓4.4后实现透明状态栏
2015-07-17 11:54
375 查看
http://blog.csdn.net/s1e1s/article/details/46558681
在安卓4.4后实现透明状态栏
基于SystemBarTint实现(SystemBarTint链接:https://github.com/jgilfelt/SystemBarTint)
第一步
首先将SystemBarTintManager类放入项目。
下载链接:http://download.csdn.net/detail/s1e1s/8821609
第二步
在activity对应的布局文件中加入两行代码
android:fitsSystemWindows="true"
android:clipToPadding="true"
[html] view
plaincopy
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:clipToPadding="true"
>
第三步
onCreat()方法中调用initSystemBar()方法
[java] view
plaincopy
<span style="white-space:pre"> </span>private void initSystemBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setTranslucentStatus(true);
}
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
//使用颜色资源
//tintManager.setStatusBarTintResource(R.color.systemBar_color);
//使用图片资源
tintManager.setStatusBarTintDrawable(getResources().getDrawable(R.drawable.ic_top_title_background));
}
<span style="white-space:pre"> </span>@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);
}
颜色资源文件
在res->values 新建color.xml
[html] view
plaincopy
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<color name="systemBar_color">#2aa45a</color><!--导航栏背景颜色 -->
</resources>
在安卓4.4后实现透明状态栏
基于SystemBarTint实现(SystemBarTint链接:https://github.com/jgilfelt/SystemBarTint)
第一步
首先将SystemBarTintManager类放入项目。
下载链接:http://download.csdn.net/detail/s1e1s/8821609
第二步
在activity对应的布局文件中加入两行代码
android:fitsSystemWindows="true"
android:clipToPadding="true"
[html] view
plaincopy
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:clipToPadding="true"
>
第三步
onCreat()方法中调用initSystemBar()方法
[java] view
plaincopy
<span style="white-space:pre"> </span>private void initSystemBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setTranslucentStatus(true);
}
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
//使用颜色资源
//tintManager.setStatusBarTintResource(R.color.systemBar_color);
//使用图片资源
tintManager.setStatusBarTintDrawable(getResources().getDrawable(R.drawable.ic_top_title_background));
}
<span style="white-space:pre"> </span>@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);
}
颜色资源文件
在res->values 新建color.xml
[html] view
plaincopy
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<color name="systemBar_color">#2aa45a</color><!--导航栏背景颜色 -->
</resources>
相关文章推荐
- AbstractFactory Pattern
- mysql命令集
- JS中call和apply区别有哪些 记录
- nginx ssl 证书报错
- 项目管理工具到底应该为谁服务?
- Toolbar的高级使用
- 如何吧Python文件转换为exe文件 pyinstaller篇
- 海归首选“北广” 薪酬期望值不要太高 元芳你怎么看?
- 查看端口被哪个进程占用了
- 利用phpmyadmin修改mysql的root密码及如何进入修改密码后的phpmyadmin
- NAND Flash的坏块管理设计
- 【Android Studio探索之路系列】之一:Android Studio开篇
- 屏幕适配问题
- ios中的c第三天循环
- 学生成绩单的制作
- Linux Min装机--配置Tomcat开机启动
- Win7小知识
- 云片网-最好用的短信服务商 短信平台
- 技能
- php -- 魔术方法 之 获取属性:__get()