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 . 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 check out the related API usage on the sidebar.
Example 1
Source File: StatusBarColorUtils.java    From QPM with 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 2
Source File: Launcher.java    From LaunchEnr with 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 3
Source File: ImmersiveModeUtil.java    From AndroidUiKit with 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 File: Util.java    From SmartSwipe with 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 5
Source File: AndroidUtilities.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
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 6
Source File: ViewUtils.java    From android-proguards with 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 7
Source File: SystemBarHelper.java    From HeroVideo-master with Apache License 2.0 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 8
Source File: SystemUtils.java    From imsdk-android with 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 9
Source File: StaticUtils.java    From SimplicityBrowser with 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 10
Source File: SystemBarHelper.java    From FlycoSystemBar with 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 11
Source File: SystemBarUtil.java    From paper-launcher with 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 12
Source File: MainActivity.java    From TreeView with 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 13
Source File: AndroidUIGuidelinesBridge.java    From CrossMobile with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 14
Source File: ImmersionBar.java    From MyBookshelf with GNU General Public License v3.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.darkFont) {
        return uiFlags | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
    } else {
        return uiFlags;
    }
}
 
Example 15
Source File: ImmersionBar.java    From ImmersionBar with 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 16
Source File: SystemUtils.java    From EasyPhotos with 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 17
Source File: StatusBarUtil.java    From StatusBarUtil with 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 18
Source File: AppUtils.java    From AndroidNavigation with 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 19
Source File: ViewUtil.java    From BaseProject with 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
                }
            }
        }
    }
 
Example 20
Source File: Presenter.java    From react-native-navigation with 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);
}