Android中沉浸式透明状态栏和导航栏的终极解决方案

转载地址:https://github.com/Zackratos/UltimateBar

UltimateBar

透明状态栏导航栏、沉浸式状态栏导航栏的终极解决方案

特点:

1.四种效果,自定义颜色的状态栏和导航栏,半透明状态栏和导航栏, 沉浸式状态栏和导航栏,隐藏状态栏和导航栏;

2.可以自定义状态栏和导航栏的颜色和透明度;

3.KITKAT(Android 4.4)和LOLLIPOP(Android 5.0)上显示效果高度统一。

使用方法:

首先添加依赖:

compile 'org.zackratos:ultimatebar:1.0.3'



1.自定义颜色的状态栏和导航栏

在 onCreate() 方法中:

UltimateBar ultimateBar = new UltimateBar(this);
ultimateBar.setColorBar(ContextCompat.getColor(this, R.color.DeepSkyBlue));



 



如果需要设置不透明度:

UltimateBar ultimateBar = new UltimateBar(this);
ultimateBar.setColorBar(ContextCompat.getColor(this, R.color.SpringGreen), 50);



 





2.半透明状态栏和导航栏

在 onCreate() 方法中:

UltimateBar ultimateBar = new UltimateBar(this);
ultimateBar.setTransparentBar(Color.BLUE, 50);



   





3.沉浸式状态栏和导航栏:

在 onCreate() 方法中:

UltimateBar ultimateBar = new UltimateBar(this);
ultimateBar.setImmersionBar();



 





4.隐藏状态栏和导航栏:

在 onWindowFocusChanged() 方法中:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        UltimateBar ultimateBar = new UltimateBar(this);
        ultimateBar.setHintBar();
    }
}



 





5.在 DrawerLayout 中设置自定义颜色的状态栏和导航栏:

首先需要设置 DrawerLayout 下面的主局部中添加 android:fitsSystemWindows="true":

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:orientation="vertical">
    </LinearLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/SpringGreen"
        android:layout_gravity="left"/>

</android.support.v4.widget.DrawerLayout>

注意是 DrawerLayout 下面的主布局,DrawerLayout 本身和抽屉布局都不能添加。

然后在 onCreate() 方法中:

UltimateBar ultimateBar = new UltimateBar(this);
ultimateBar.setColorBarForDrawer(ContextCompat.getColor(this, R.color.DeepSkyBlue));



  

如果需要设置不透明度:

UltimateBar ultimateBar = new UltimateBar(this);
ultimateBar.setColorBarForDrawer(ContextCompat.getColor(this, R.color.DeepSkyBlue), 50);





更新日志

v1.0.3

1.在 Android 4.4 中使用自定义颜色的状态栏和导航栏的时候,如果没有导航栏,不设置导航栏。

v1.0.2

1.增加 DrawerLayout 使用的自定义颜色的状态栏和导航栏。

v1.0.1

1.判断当状态栏不存在时,不对状态栏进行设置;

2.自定义颜色的状态栏和导航栏中,当加深程度为 0 时,直接设置为原颜色,即不加深颜色;

3.半透明的状态栏和导航栏中,当不透明度为 0 时,直接设为完全透明,即不进行不透明度计算;

4.修改包名。

v1.0.0

1.四种效果,自定义颜色的状态栏和导航栏,半透明状态栏和导航栏, 沉浸式状态栏和导航栏,隐藏状态栏和导航栏;

2.可以自定义状态栏和导航栏的颜色和透明度;

3.KITKAT(Android 4.4)和LOLLIPOP(Android 5.0)上显示效果高度统一。

License

Copyright 2017 Zackratos

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
参考文章: https://mp.weixin.qq.com/s/MHAhvGLMLiFHK-FgH964sw
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值