Home

Awesome

目录介绍

0.说明

1.关于如何集成

implementation 'com.github.yangchong211.YCStatusBar:StatusBarLib:1.4.6'

2.关于如何使用

//为DrawerLayout 布局设置状态栏颜色,纯色
DlStatusBar.setColorNoTranslucentForDrawerLayout(this, drawerLayout,getResources().getColor(R.color.colorTheme));
//为DrawerLayout 布局设置状态栏变色,也就是加上透明度
DlStatusBar.setColorForDrawerLayout(this, drawerLayout,getResources().getColor(R.color.colorTheme), 0);
StateAppBar.setStatusBarColor(this, ContextCompat.getColor(this, R.color.colorAccent));
StateAppBar.setStatusBarColor(this, ContextCompat.getColor(this, R.color.colorAccent));
StateAppBar.translucentStatusBar(this, true);
StateAppBar.setStatusBarColor(this, ContextCompat.getColor(this, R.color.colorPrimary));
StateAppBar.setStatusBarColorForCollapsingToolbar(this, mAppBarLayout, collapsingToolbarLayout, toolbar, ContextCompat.getColor(this, R.color.colorPrimary));
StateAppBar.setStatusBarLightMode(this, Color.WHITE);
StateAppBar.setStatusBarLightMode(this, Color.WHITE);
StateAppBar.setStatusBarLightForCollapsingToolbar(this, mAppBarLayout, collapsingToolbarLayout, toolbar, Color.WHITE);
//例如,ViewPager+TabLayout+Fragment中,很常见
@Override
public void onPageSelected(int position) {
    switch (position){
        case 0:
            //设置状态栏为黑色
            StateAppBar.setStatusBarColor(StatusBarFragmentActivity.this,
                    ContextCompat.getColor(StatusBarFragmentActivity.this,
                            R.color.colorTheme));
            break;
        case 1:
            //设置状态栏为红色
            StateAppBar.setStatusBarColor(StatusBarFragmentActivity.this,
                    ContextCompat.getColor(StatusBarFragmentActivity.this,
                            R.color.colorAccent));
            break;
        case 2:
            //设置状态栏为蓝色
            StateAppBar.setStatusBarColor(StatusBarFragmentActivity.this,
                    ContextCompat.getColor(StatusBarFragmentActivity.this,
                            R.color.colorPrimary));
            break;
        case 3:
            //设置状态栏为透明,相当于隐藏状态栏,也称之为沉浸式状态栏
            StateAppBar.translucentStatusBar(StatusBarFragmentActivity.this,
                    true);
            break;
        case 4:
            //设置状态栏为白色
            StateAppBar.setStatusBarColor(StatusBarFragmentActivity.this,
                    ContextCompat.getColor(StatusBarFragmentActivity.this,
                            R.color.white));
            //状态栏亮色模式,设置状态栏黑色文字、图标
            StatusBarUtils.StatusBarLightMode(StatusBarFragmentActivity.this);
            break;
    }
}
//在activity中
StateAppBar.translucentStatusBar(this,true);

//在fragment中
//判断是否展示—与ViewPager连用,进行左右切换
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    if (isVisibleToUser){
        if(activity!=null){
            StateAppBar.setStatusBarColor(activity, ContextCompat.getColor(activity, R.color.white));
            //状态栏亮色模式,设置状态栏黑色文字、图标
            //注意:如果是设置白色状态栏,则需要添加下面这句话。如果是设置其他的颜色,则可以不添加,状态栏大都默认是白色字体和图标
            StatusBarUtils.StatusBarLightMode(activity);
        }
    }//展示
}
//状态栏亮色模式,设置状态栏黑色文字、图标
StatusBarUtils.StatusBarLightMode(StatusBarFragmentActivity.this);

3.关于鸣谢

4.关于版本更新说明

5.出现的bug及解决方案,欢迎提出更多bug

6.状态栏系列文档

6.关于其他介绍

关于我的博客