Java Code Examples for android.view.View#SYSTEM_UI_FLAG_LIGHT_STATUS_BAR

The following examples show how to use android.view.View#SYSTEM_UI_FLAG_LIGHT_STATUS_BAR . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
public static void setLightStatusBar(Window window, boolean enable) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        final View decorView = window.getDecorView();
        int flags = decorView.getSystemUiVisibility();
        if (enable) {
            if ((flags & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) == 0) {
                flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
                decorView.setSystemUiVisibility(flags);
                window.setStatusBarColor(0x0f000000);
            }
        } else {
            if ((flags & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) != 0) {
                flags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
                decorView.setSystemUiVisibility(flags);
                window.setStatusBarColor(0x33000000);
            }
        }
    }
}
 
Example 2
Source Project: SmartSwipe   File: Util.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean setStatusBarTransparent(Activity activity, boolean darkStatusBar) {
    View decorView = activity.getWindow().getDecorView();
    boolean isInMultiWindowMode = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && activity.isInMultiWindowMode();
    if (isInMultiWindowMode || Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return false;
    } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    } else {
        int systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
        if (darkStatusBar && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            systemUiVisibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        }
        decorView.setSystemUiVisibility(systemUiVisibility);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    }
    return true;
}
 
Example 3
Source Project: AndroidUiKit   File: ImmersiveModeUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 已在style中配置
 * 官方及主流rom
 *
 * @param activity
 * @param darkmode
 */
public static boolean setCommonStatusBarDarkMode(@NonNull Activity activity, boolean isFontColorDark) {
    boolean result = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        View decor = activity.getWindow().getDecorView();
        int ui = decor.getSystemUiVisibility();
        if (isFontColorDark) {
            ui |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        } else {
            ui &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        }
        decor.setSystemUiVisibility(ui);
        // api>=23 默认成功
        result = true;
    }
    return result;
}
 
Example 4
Source Project: LaunchEnr   File: Launcher.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sets the status and/or nav bar to be light or not. Light status bar means dark icons.
 * @param isLight make sure the system bar is light.
 * @param statusBar if true, make the status bar theme match the isLight param.
 * @param navBar if true, make the nav bar theme match the isLight param.
 */
@TargetApi(23)
public void activateLightSystemBars(boolean isLight, boolean statusBar, boolean navBar) {
    int oldSystemUiFlags = getWindow().getDecorView().getSystemUiVisibility();
    int newSystemUiFlags = oldSystemUiFlags;
    if (isLight) {
        if (statusBar) {
            newSystemUiFlags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        }
        if (navBar && AndroidVersion.isAtLeastOreo()) {
            newSystemUiFlags |= SYSTEM_UI_FLAG_LIGHT_NAV_BAR;
        }
    } else {
        if (statusBar) {
            newSystemUiFlags &= ~(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
        if (navBar && AndroidVersion.isAtLeastOreo()) {
            newSystemUiFlags &= ~(SYSTEM_UI_FLAG_LIGHT_NAV_BAR);
        }
    }

    if (newSystemUiFlags != oldSystemUiFlags) {
        getWindow().getDecorView().setSystemUiVisibility(newSystemUiFlags);
    }
}
 
Example 5
Source Project: QPM   File: StatusBarColorUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 设置状态栏颜色 6.0以上
 *
 * @param window
 * @param dark
 */
@RequiresApi(api = Build.VERSION_CODES.M)
private static boolean setStatusBarDarkIcon6(Window window, boolean dark) {
    boolean result = false;
    View view = window.getDecorView();
    if (view != null) {
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        int oldVis = view.getSystemUiVisibility();
        int newVis = oldVis;
        if (dark) {
            newVis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        } else {
            newVis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        }
        if (newVis != oldVis) {
            view.setSystemUiVisibility(newVis);
        }
        result = true;
    }
    return result;
}
 
Example 6
/**
 * android 6.0设置字体颜色
 */
@TargetApi(Build.VERSION_CODES.M)
public static void setStatusBarDarkModeForM(Window window) {

  window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
  window.setStatusBarColor(Color.TRANSPARENT);

  int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
  systemUiVisibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
  window.getDecorView().setSystemUiVisibility(systemUiVisibility);
}
 
Example 7
Source Project: AndroidNavigation   File: AppUtils.java    License: MIT License 5 votes vote down vote up
public static void setStatusBarStyle(Window window, boolean dark) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        View decorView = window.getDecorView();
        int systemUi = decorView.getSystemUiVisibility();
        if (dark) {
            systemUi |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        } else {
            systemUi &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        }
        decorView.setSystemUiVisibility(systemUi);
    }
}
 
Example 8
Source Project: StatusBarUtil   File: StatusBarUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * android 6.0设置字体颜色
 *
 * @param window 目标window
 * @param dark   亮色 or 暗色
 */
@RequiresApi(Build.VERSION_CODES.M)
private static void darkModeForM(Window window, boolean dark) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
        if (dark) {
            systemUiVisibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        } else {
            systemUiVisibility &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        }
        window.getDecorView().setSystemUiVisibility(systemUiVisibility);
    }
}
 
Example 9
Source Project: EasyPhotos   File: SystemUtils.java    License: Apache License 2.0 5 votes vote down vote up
private void setStatusTextBlackAndroid(Activity activity, boolean darkmode) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        Window window = activity.getWindow();
        if (darkmode) {
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        } else {
            int flag = window.getDecorView().getSystemUiVisibility() & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
            window.getDecorView().setSystemUiVisibility(flag);
        }
    }
}
 
Example 10
Source Project: ImmersionBar   File: ImmersionBar.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets status bar dark font.
 * 设置状态栏字体颜色,android6.0以上
 */
private int setStatusBarDarkFont(int uiFlags) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && mBarParams.statusBarDarkFont) {
        return uiFlags | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
    } else {
        return uiFlags;
    }
}
 
Example 11
/**
 * Sets status bar dark font.
 * 设置状态栏字体颜色,android6.0以上
 */
private int setStatusBarDarkFont(int uiFlags) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && mBarParams.darkFont) {
        return uiFlags | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
    } else {
        return uiFlags;
    }
}
 
Example 12
private void setStatusBarText(Window window, boolean dark) {
    int visibility = window.getDecorView().getSystemUiVisibility();
    if (dark)
        visibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
    else
        visibility &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
    window.getDecorView().setSystemUiVisibility(visibility);
}
 
Example 13
Source Project: TreeView   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void setLightStatusBar(@NonNull View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        int flags = view.getSystemUiVisibility();
        getWindow().setStatusBarColor(Color.WHITE);
        flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        view.setSystemUiVisibility(flags);
    }
}
 
Example 14
Source Project: paper-launcher   File: SystemBarUtil.java    License: MIT License 5 votes vote down vote up
public static void enableLightStatusBar(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        View view = activity.getWindow().getDecorView();

        int flags = view.getSystemUiVisibility();
        flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        view.setSystemUiVisibility(flags);
    }
}
 
Example 15
Source Project: FlycoSystemBar   File: SystemBarHelper.java    License: MIT License 5 votes vote down vote up
/** android 6.0设置字体颜色 */
@TargetApi(Build.VERSION_CODES.M)
public static void setStatusBarDarkModeForM(Window window) {
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(Color.TRANSPARENT);

    int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
    systemUiVisibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
    window.getDecorView().setSystemUiVisibility(systemUiVisibility);
}
 
Example 16
Source Project: SimplicityBrowser   File: StaticUtils.java    License: MIT License 5 votes vote down vote up
public static void setLightStatusBar(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        int flags = activity.getWindow().getDecorView().getSystemUiVisibility(); // get current flag
        flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;   // add LIGHT_STATUS_BAR to flag
        activity.getWindow().getDecorView().setSystemUiVisibility(flags);
    }
}
 
Example 17
Source Project: imsdk-android   File: SystemUtils.java    License: MIT License 5 votes vote down vote up
private void setStatusTextBlackAndroid(Activity activity, boolean darkmode) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        Window window = activity.getWindow();
        if (darkmode) {
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        } else {
            int flag = window.getDecorView().getSystemUiVisibility() & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
            window.getDecorView().setSystemUiVisibility(flag);
        }
    }
}
 
Example 18
Source Project: android-proguards   File: ViewUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void setLightStatusBar(@NonNull View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        int flags = view.getSystemUiVisibility();
        flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        view.setSystemUiVisibility(flags);
    }
}
 
Example 19
Source Project: react-native-navigation   File: Presenter.java    License: MIT License 4 votes vote down vote up
private void clearDarkTextColorScheme(View view) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
    int flags = view.getSystemUiVisibility();
    flags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
    view.setSystemUiVisibility(flags);
}
 
Example 20
Source Project: BaseProject   File: ViewUtil.java    License: Apache License 2.0 4 votes vote down vote up
/**
     * 代码的方式来设置沉浸式界面
     * @param curActivity 当前Activity
     * @param needFullScreen 是否需要全屏:一般为false
     * @param translucentNavBar 是否需要透明导航栏:一般为true
     * @param hideNavigation 是否要隐藏导航栏: 一般为true
     * @param drawStatusBarBg 是否需要在Android 5.0及以上 接管状态栏背景绘制,用于指定 状态栏背景颜色
     * @param statusBarColor 想要的状态栏颜色
     * @param isLightStatusBar 是否需要在Android 6.0及以上 启用状态栏的灰色文字和图标
     */
    public static void immersiveScreen(Activity curActivity,boolean needFullScreen,
                                       boolean translucentNavBar,boolean hideNavigation,
                                       boolean drawStatusBarBg, int statusBarColor,boolean isLightStatusBar) {
        if (curActivity != null) {
            Window window = curActivity.getWindow();
            if (window != null) {
                WindowManager.LayoutParams windowParams = window.getAttributes();
                if (windowParams != null) {
                    //已经存在的 可见性参数
                    int mayExistVisibility = windowParams.systemUiVisibility;
//                    int mayExistFlags = windowParams.flags;
                    int curSdkInt = Build.VERSION.SDK_INT;
                    if (needFullScreen) {
//                        mayExistFlags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
                        window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                    }

                    if (curSdkInt >= 19) {//Android 4.4后才有沉浸式
                        if (translucentNavBar) {
//                            mayExistFlags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
                            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
                        }
                        //默认的实现沉浸式flag
                        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

                        if (curSdkInt >= 21) {
                            if (drawStatusBarBg) {//如果需要 代替绘制状态栏的背景,则需要清除 FLAG_TRANSLUCENT_STATUS
                                window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                            }
                            if (statusBarColor != -1) {
                                window.setStatusBarColor(statusBarColor);
                            }
                            if (curSdkInt >= 23) {//Android 6.0以上 实现状态栏字色和图标浅黑色
                                if (isLightStatusBar) {
                                    mayExistVisibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
                                }
                            }
                        }
                        if (hideNavigation) {//隐藏导航栏
                            mayExistVisibility |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                                    | View.SYSTEM_UI_FLAG_IMMERSIVE
                                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                            ;
                            windowParams.systemUiVisibility = mayExistVisibility;
                            window.setAttributes(windowParams);
                        }
                    }//curSdkInt >= 19 end
                }
            }
        }
    }