This commit is contained in:
@ -18,13 +18,16 @@ import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.ColorRes;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
|
||||
import com.halo.assistant.HaloApp;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
public class DisplayUtils {
|
||||
|
||||
/**
|
||||
@ -223,6 +226,27 @@ public class DisplayUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setStatusBarColor(Activity activity, @ColorRes int colorRes) {
|
||||
Window window = activity.getWindow();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
int colorInt = ContextCompat.getColor(activity, colorRes);
|
||||
// 设置状态栏底色颜色
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
window.setStatusBarColor(colorInt);
|
||||
// 如果亮色,设置状态栏文字为黑色
|
||||
if (isLightColor(colorInt)) {
|
||||
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
} else {
|
||||
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isLightColor(@ColorInt int color) {
|
||||
return ColorUtils.calculateLuminance(color) >= 0.5;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isMiuiOs() {
|
||||
String property = getSystemProperty("ro.miui.ui.version.name", "");
|
||||
|
||||
Reference in New Issue
Block a user