Android 状态栏工具类(实现沉浸式状态栏/变色状态栏)
生活随笔
收集整理的這篇文章主要介紹了
Android 状态栏工具类(实现沉浸式状态栏/变色状态栏)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
From:寫代碼的猴子
這是一個(gè)為Android App 設(shè)置狀態(tài)欄的工具類, 可以在4.4及其以上系統(tǒng)中實(shí)現(xiàn) 沉浸式狀態(tài)欄/狀態(tài)欄變色,支持設(shè)置狀態(tài)欄透明度,滿足你司設(shè)計(jì)師的各種要求(霧)。
在此之前我寫過(guò)一篇Android App 沉浸式狀態(tài)欄解決方案,后來(lái)我司設(shè)計(jì)師說(shuō)默認(rèn)的透明度太深了,讓我改淺一點(diǎn),然后在想了一些辦法之后給解決了。本著不重復(fù)造輪子的原則,索性整理成一個(gè)工具類,方便需要的開(kāi)發(fā)者。
項(xiàng)目 GitHub 地址
Sample 下載
下載 StatusBarUtil-Demo
特性
1. 設(shè)置狀態(tài)欄顏色
StatusBarUtil.setColor(Activity activity, int color)
2. 設(shè)置狀態(tài)欄半透明
StatusBarUtil.setTranslucent(Activity activity, int statusBarAlpha)
3. 設(shè)置狀態(tài)欄全透明
StatusBarUtil.setTransparent(Activity activity)
4. 為包含?DrawerLayout?的界面設(shè)置狀態(tài)欄顏色(也可以設(shè)置半透明和全透明)
StatusBarUtil.setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, int color)
5. 通過(guò)傳入?statusBarAlpha?參數(shù),可以改變狀態(tài)欄的透明度值,默認(rèn)值是112。
使用
1. 在 build.gradle 文件中添加依賴, StatusBarUtil 已經(jīng)發(fā)布在 JCenter:
compile 'com.jaeger.statusbaruitl:library:1.0.0'2. 在?setContentView()?之后調(diào)用你需要的方法,例如:
setContentView(R.layout.main_activity); ... StatusBarUtil.setColor(MainActivity.this, mColor);3. 如果你在一個(gè)包含?DrawerLayout?的界面中使用, 你需要在布局文件中為?DrawerLayout?添加?android:fitsSystemWindows="true"?屬性:
<android.support.v4.widget.DrawerLayoutxmlns: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. 當(dāng)你設(shè)置了?statusBarAlpha?值時(shí),該值需要在 0 ~ 255 之間
最后
如果你有任何建議或問(wèn)題,請(qǐng)及時(shí)聯(lián)系我。如果你對(duì)這個(gè)工具類有優(yōu)化,歡迎 fork 提 pr。
傳送門 GitHub 地址
總結(jié)
以上是生活随笔為你收集整理的Android 状态栏工具类(实现沉浸式状态栏/变色状态栏)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: GeneXus学习记录——Transac
- 下一篇: uva 1218