Need help with StatusBarUtil?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

laobie
8.7K Stars 1.7K Forks Apache License 2.0 73 Commits 107 Opened issues

Description

A util for setting status bar style on Android App.

Services available

!
?

Need anything else?

Contributors list

# 3,040
Java
Android
statusb...
Python
57 commits
# 22,377
Java
TypeScr...
Shell
android...
4 commits
# 52,653
Kotlin
Java
compres...
Android
1 commit
# 14,147
Java
Android
xposed
Kotlin
1 commit
# 48,757
Dart
Socket....
retrofi...
Java
1 commit
# 39,001
Java
image-c...
statusb...
Android
1 commit
# 52,526
statusb...
Java
Android
intelli...
1 commit

StatusBarUtil

招人广告:

字节跳动各业务线均可内推,可直接推我现在所在的部门 TikTok/抖音 业务线,提供以下服务:

  • 简历修改
  • 面试指导
  • 进度跟进

欢迎看机会的人加我微信,也欢迎进行技术交流。

Lark20210629-164537.jpg

Android Arsenal

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

中文版点我

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>

  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.java

Handle all Fragments in ViewPager as ImageViewFragment, add a fake View in your Fragment layout as StatusBar :

   
   

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

   <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"></textview>   

The fake StatusBar View height value

statusbar_view_height
defined in
dimens.xml
   ~ values-v19/dimens.xml

25dp

~ values/dimens.xml

0dp

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)

  • 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)
![](img/switch_light_mode.jpeg)
  • Use in fragment

  • Set color for swipe back page
    StatusBarUtil.setColorForSwipeBack(Activity activity, @ColorInt int color, int statusBarAlpha)
![](img/set_color_for_swipe_back_page.png)
  • Pass statusBarAlpha param when necessary to change your status bar alpha, which is 112 by default.

License

Copyright 2016 Jaeger Chen

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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.