Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

StatusBarUtil

> 编程语言
Open source

A util for setting status bar style on Android App.

8.8K stars0 likes1 views
WebsiteGitHub

About

A util for setting status bar style on Android App.

StatusBarUtil

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:

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

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

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

    java
    setContentView(R.layout.main_activity);
    ...
    StatusBarUtil.setColor(MainActivity.this, mColor);
  3. If you use this util in a page which containing a DrawerLayout, you need add android:fitsSystemWindows="true" for DrawerLayout in your layout XML:

    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>
  4. Set color for swipe back page

    Recommend using with bingoogolapple/BGASwipeBackLayout-Android: Android Activity 滑动返回

    java
    StatusBarUtil.setColorForSwipeBack(Activity activity, @ColorInt int color, int statusBarAlpha)
  5. All statusBarAlpha value you set should between 0 ~ 255

  6. 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 :

…

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

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 :

java
mFakeStatusBar.setBackgroundColor(color);

Then in the Activity which contains ViewPage, just invoke

java
StatusBarUtil.setTranslucentForImageViewInFragment(UseInFragmentActivity.this, null);

Please read UseInFragmentActivity.java

Features

  • Set status bar color

    java
    StatusBarUtil.setColor(Activity activity, int color)
  • Set status bar translucent

    java
    StatusBarUtil.setTranslucent(Activity activity, int statusBarAlpha)
  • Set status bar transparent

    java
    StatusBarUtil.setTransparent(Activity activity)
  • Set status bar color for DrawerLayout

    java
    StatusBarUtil.setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, int color)
  • Set translucent status bar for using ImageView as head view page

    java
      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

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

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.

Issues· 112 open

View all issuesOpen on GitHub
  • #303

    [BUG]StrandHogg2.0 Restoration suggestions

    Updated Apr 16, 2025
  • #302

    兄弟们,这个库作者好久没更新了,有没有其他的同类型的优秀库推荐一下啊,快来交流一下

    Updated Feb 1, 2024
  • #301

    在清单文件里设置 android:windowSoftInputMode="adjustResize|stateHidden"软键盘不会顶起布局导致输入框被遮挡

    Updated Sep 2, 2023
  • #300

    小米V130 com.jaeger.library.StatusBarUtil.setLightMode 报错org.json.JSONException: No value for cezanne

    Updated Feb 22, 2023
  • #299

    1.5.1版本build失败

    Updated Aug 3, 2022
  • #292

    异形屏statusbar高度太低,导致内容被覆盖

    Updated Mar 2, 2022
  • #291

    setDarkMode 和 setLightMode 会使 布局向上偏移,设置fitsSystemWindows会使Edittextview长按上下文菜单边距失效

    Updated Dec 10, 2021
  • #296

    不维护了?什么时候适配水滴和挖孔屏

    Updated Dec 2, 2021
  • #295

    有个StatusBarUtils的报错 能看下么

    Updated Mar 9, 2021
  • #294

    Status bar

    Updated Dec 20, 2020

> Tags

Javaandroidstatusbarstatusbarutilutils

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 29, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言