适用于版本大于等于19以上。
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
/**
* Created by zhy on 15/9/21.
*/
public class StatusBarCompat
{
private static final int INVALID_VAL = -1;
private static final int COLOR_DEFAULT = Color.parseColor("#20000000");
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void compat(Activity activity, int statusColor)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
if (statusColor != INVALID_VAL)
{
activity.getWindow().setStatusBarColor(statusColor);
}
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT 0)
{
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
}
用法:
Activiy onCreate中添加:
StatusBarCompat.compat(this);
如果需要制定状态栏颜色,使用此方法:
StatusBarCompat.compat(this, 0xFFFF0000);
https://github.com/hongyangAndroid/ColorfulStatusBar
为Android4.4以上系统的状态栏和导航栏填充颜色
https://github.com/jgilfelt/SystemBarTint
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net