Android 4.4浸漬ステータスバー実装

4583 ワード

スタイルスタイルに次のitem(場所:res/values/styles.xml)を追加します.
 	true
        true

完全なコードは次のとおりです.

なお、この場合のステータスバーは場所を占有せず、スタイルに次の構成を追加する必要があります.
name="android:fitsSystemWindows">true

次に、BaseActivityのonCreateメソッドで次のメソッドを呼び出します.
private void initSystemBar() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            tintManager.setStatusBarTintEnabled(true);
// Holo light action bar color is #DDDDDD
            int actionBarColor = Color.parseColor("#1a92fe");
            tintManager.setStatusBarTintColor(actionBarColor);
        }
    }

ここではオープンソースライブラリを使用します
アドレス:https://github.com/jgilfelt/SystemBarTint
build.gradleで追加
dependencies {
    compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
}