How to set Status bar to white background and blac

2019-02-26 02:27发布

I want to set the status bar to white background and black text(and black icon) in my app. I found some apps can do this. But search from google, I can not found any solution to do this.There is a lot solutions about how to set status bar's color.Also like SystemBarTint ,It just can set background, but not set the whole status bar's style(white background and black text OR black background and white text color).

3条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-02-26 02:49

Its for API 21 Or greator

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                Window window = getWindow();
                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                window.setStatusBarColor(getResources()
                        .getColor(R.color.YOurColorname));
            }
查看更多
ゆ 、 Hurt°
3楼-- · 2019-02-26 02:56

Place this is your values-v21/styles.xml, to enable this on Lollipop: It will only work above API 21

  <resources>
        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light">
            <item name="colorPrimary">@color/color_primary</item>
            <item name="colorPrimaryDark">@color/color_secondary</item>
            <item name="colorAccent">@color/color_accent</item>
            <item name="android:statusBarColor">@color/color_primary</item>
        </style>
    </resources>
查看更多
劳资没心,怎么记你
4楼-- · 2019-02-26 02:59

I found this solution use this code:

  getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
 getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 
  getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

getWindow().setStatusBarColor(Color.TRANSPARENT);// SDK21
查看更多
登录 后发表回答