Java tutorial
//package com.java2s; import android.app.Activity; import android.view.Window; import java.lang.reflect.Field; import java.lang.reflect.Method; public class Main { private static boolean setMiuiStatusBarDarkMode(Activity activity, boolean darkmode) { Class<? extends Window> clazz = activity.getWindow().getClass(); try { int darkModeFlag = 0; Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams"); Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE"); darkModeFlag = field.getInt(layoutParams); Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class); extraFlagField.invoke(activity.getWindow(), darkmode ? darkModeFlag : 0, darkModeFlag); return true; } catch (Exception e) { e.printStackTrace(); } return false; } }