因为只有6.0以上的系统才支持状态栏字体颜色的设置,6.0一下的部分手机可通过修改系统源码来进行设置如小米,魅族。
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;
import android.view.Window;
import android.view.WindowManager;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* 状态栏颜色字体设置
* Created by dell on 2016/10/26.
*/
public class BarTextColorUtils {
public static int StatusBarLightMode(Activity activity){
int result=0;
//这个方法只支持4.0以上系统
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if(MIUISetStatusBarLightMode(activity.getWindow(), true)){//判断是不是小米系统
result=1;
}else if(FlymeSetStatusBarLightMode(activity.getWindow(), true)){//判断是不是魅族系统
result=2;
}else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {//判断当前是不是6.0以上的系统
activity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
setTranslucentForCoordinatorLayout(activity, 255);