Android 多变的,有范的沉浸式状态栏(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);

好了,别人的我转载一下,有什么不会的仔细看楼,挺简单的。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值