使用案例(Kotlin)
//沉浸式实现
StatusBarUtil.immersive(this)
//填充View
//id:控件id
StatusBarUtil.setPaddingSmart(this, id)
//状态栏字体颜色
//true:黑色
//false:白色
StatusBarUtil.darkMode(this, false)
//状态栏颜色
//activity
//color(状态栏颜色值)
//alpha(透明度,取值范围 0.0f - 1.0f )
StatusBarUtil.darkMode(this, resources.getColor(R.color.color_00ff00), 0.5f)
工具类 StatusBarUtil
@SuppressWarnings(“unused”)
public class StatusBarUtil {
public static int DEFAULT_COLOR = 0;
public static float DEFAULT_ALPHA = 0;//Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? 0.2f : 0.3f;
public static final int MIN_API = 17;
//沉浸式
public static void immersive(Activity activity) {
immersive(activity, DEFAULT_COLOR, DEFAULT_ALPHA);
}
public static void immersive(Activity activity, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) {
immersive(activity.getWindow(), color, alpha);
}
public static void immersive(Activity activity, int color) {
immersive(activity.getWindow(), color, 1f);
}
public static void immersive(Window window) {
immersive(window, DEFAULT_COLOR, DEFAULT_ALPHA);
}
public static void immersive(Window window, int color) {
immersive(window, color, 1f);
}
@SuppressLint(“ObsoleteSdkInt”)
public static void immersive(Window window, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) {
if (Build.VERSION.SDK_INT >= 21) {
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(mixtureColor(color, alpha));
int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STA