您的位置:首页 > 其它

安卓4.4后实现透明状态栏

2015-06-19 10:08 239 查看
在安卓4.4后实现透明状态栏

基于SystemBarTint实现(SystemBarTint链接:https://github.com/jgilfelt/SystemBarTint)

第一步

首先将SystemBarTintManager类放入项目。

下载链接:http://download.csdn.net/detail/s1e1s/8821609

第二步

在activity对应的布局文件中加入两行代码
android:fitsSystemWindows="true"

android:clipToPadding="true"

<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()方法

<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

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<color name="systemBar_color">#2aa45a</color><!--导航栏背景颜色 -->

</resources>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: