laobie / StatusBarUtil

A util for setting status bar style on Android App.
http://t.cn/Rq746Kb
Apache License 2.0
8.81k stars 1.72k forks source link

兄弟,怎么把状态栏的字体颜色也改变,在线等 #137

Closed haegyeong closed 6 years ago

laobie commented 7 years ago

我也不会啊,Google 会

RyanYans commented 7 years ago

同需求呀,ui设计个破图,在同一activity下的两个fragment上去改状态栏字体颜色,丧心病狂啊

haegyeong commented 7 years ago

@RyanYans 兄弟,我是这样写的实现改变黑白字体的,配合这个库https://github.com/msdx/status-bar-compat,我没在fragment试过,你可以尝试一下,希望能帮到你 @TargetApi(Build.VERSION_CODES.LOLLIPOP) protected void setWhiteStatusBar() { StatusBarCompat.setStatusBarColor(this, R.color.black); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { Window window=getWindow(); //取消设置透明状态栏,使 ContentView 内容不再覆盖状态栏 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

//需要设置这个 flag 才能调用 setStatusBarColor 来设置状态栏颜色 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); //设置状态栏颜色 window.setStatusBarColor(getResources().getColor(R.color.white));

        ViewGroup mContentView = (ViewGroup)findViewById(Window.ID_ANDROID_CONTENT);
        View mChildView = mContentView.getChildAt(0);
        if(mChildView !=null){
            //注意不是设置 ContentView 的 FitsSystemWindows, 而是设置 ContentView 的第一个子 View . 预留出系统 View 的空间.
            ViewCompat.setFitsSystemWindows(mChildView,true);
        }
    }

}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void setBlackStatusBar() {
    StatusBarCompat.setStatusBarColor(this, R.color.white);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
        Window window=getWindow();

//取消设置透明状态栏,使 ContentView 内容不再覆盖状态栏 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

//需要设置这个 flag 才能调用 setStatusBarColor 来设置状态栏颜色 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); //设置状态栏颜色 window.setStatusBarColor(getResources().getColor(R.color.black));

        ViewGroup mContentView = (ViewGroup)findViewById(Window.ID_ANDROID_CONTENT);
        View mChildView = mContentView.getChildAt(0);
        if(mChildView !=null){
            //注意不是设置 ContentView 的 FitsSystemWindows, 而是设置 ContentView 的第一个子 View . 预留出系统 View 的空间.
            ViewCompat.setFitsSystemWindows(mChildView,true);
        }
    }
}
RyanYans commented 7 years ago

https://github.com/gyf-dev/ImmersionBar

lmdiloveu commented 6 years ago

同求!

laobie commented 6 years ago

1.5 版本已经添加设置状态栏模式方法,请更新到最新版本

  StatusBarUtil.setLightMode(Activity activity)
  StatusBarUtil.setDarkMode(Activity activity)