0
点赞
收藏
分享

微信扫一扫

StatusBarUtil 大神用的工具类


https://github.com/laobie/StatusBarUtil

git 地址如上

集成方法如下

StatusBarUtil

A util for setting status bar style on Android App. It can work above API 19(KitKat 4.4).

中文版点我

StatusBarUtil   大神用的工具类_android

Sample

Download StatusBarUtil-Demo

ChangeLog

CLICK ME

Usage

  1. Add the dependencies to your build.gradle file, StatusBarUtil is avaiable in JCenter:

compile 'com.jaeger.statusbarutil:library:1.5.1'

I fixed typo, change "statusbaruitl" to "statusbarutil", please notice this.

  1. Call method you need after setContentView(), such as :

setContentView(R.layout.main_activity);
...
StatusBarUtil.setColor(MainActivity.this, mColor);

  1. If you use this util in a page which containing a DrawerLayout, you need add android:fitsSystemWindows="true" for DrawerLayout in your layout XML:

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

    ...

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

  1. Set color for swipe back page
    Recommend using with bingoogolapple/BGASwipeBackLayout-Android: Android Activity 滑动返回

StatusBarUtil.setColorForSwipeBack(Activity activity, @ColorInt int color, int statusBarAlpha)

  1. All statusBarAlpha value you set should between 0 ~ 255
  2. How to use in Fragment, please read UseInFragmentActivity.javaHandle all Fragments in ViewPager as ImageViewFragment, add a fake View in your Fragment layout as StatusBar :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <View
        android:id="@+id/fake_statusbar_view"
        android:layout_width="match_parent"
        android:layout_height="@dimen/statusbar_view_height"
        android:background="@color/colorPrimary"/>

    <TextView
        android:id="@+id/tv_title"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:background="@color/colorPrimary"
        android:gravity="center"
        android:text="@string/app_name"
        android:textColor="@color/white"
        android:textSize="24sp"/>   
</LinearLayout>

The fake StatusBar View height value statusbar_view_height defined in dimens.xml

~ values-v19/dimens.xml

<dimen name="statusbar_view_height">25dp</dimen>

~ values/dimens.xml

<dimen name="statusbar_view_height">0dp</dimen>

When you change StatusBarColor :

mFakeStatusBar.setBackgroundColor(color);

Then in the Activity which contains ViewPage, just invoke

StatusBarUtil.setTranslucentForImageViewInFragment(UseInFragmentActivity.this, null);

Please read UseInFragmentActivity.java

Features

  • Set status bar color

StatusBarUtil.setColor(Activity activity, int color)

StatusBarUtil   大神用的工具类_android_02

  • Set status bar translucent

StatusBarUtil.setTranslucent(Activity activity, int statusBarAlpha)

  • Set status bar transparent

StatusBarUtil.setTransparent(Activity activity)

  • Set status bar color for DrawerLayout

StatusBarUtil.setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, int color)

  • Set translucent status bar for using ImageView as head view page

StatusBarUtil.setTranslucentForImageView(Activity activity, int statusBarAlpha, View needOffsetView)

  • Set Light or Dark mode

StatusBarUtil.setLightMode(Activity activity)
  StatusBarUtil.setDarkMode(Activity activity)

  • Use in fragment
  • Set color for swipe back page

StatusBarUtil.setColorForSwipeBack(Activity activity, @ColorInt int color, int statusBarAlpha)

  • Pass statusBarAlpha param when necessary to change your status bar alpha, which is 112 by default.

把这个放在BaseActivity的onCreate下面 更是如虎添翼

super.onCreate(savedInstanceState);
        //去掉标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //状态栏透明
        StatusBarUtil.setTranslucent(this);

 我们也用这种工具类但是随着时间的流逝和版本迭代速度 还是最好用开源的 每当文档不够新的时候 就去git 找下最新版本

举报

相关推荐

0 条评论