📜  在 android 中重置状态栏颜色 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:16.188000             🧑  作者: Mango

代码示例1
public static void changeStatusBarColor(Activity context, boolean change, int color){
    if (Build.VERSION.SDK_INT >= 21)
    {
        Window window = context.getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

        if(change){
            defaultStatusBarColor = window.getStatusBarColor();
            window.setStatusBarColor(color);
        }
        else{
            // reset
            window.setStatusBarColor(defaultStatusBarColor);
        }
    }
}