6

The default tint of status bar in Android is white(so it some kind of soppos that status bar will be dark): enter image description here I've found that I can change tint in Android versions greater or equal to 23. But then I found out that several apps on my device(Android 5.1, API 22) use black tints. How did they did it?

Update: This is what I mean: Some other App have light status bar and black icons, time label and so on.

enter image description here

This is my App sample with white status bar:

enter image description here

I can't set windowLightStatusBar as true to make it looks like app from first picture in devices with API < 23.

Community
  • 1
  • 1
  • setStatusBarColor was added in 21, not 23. So they're using that on your phone. – Gabe Sechan Jul 24 '16 at 16:07
  • @GabeSechan setStatusBarColor can only set color of my statusBar, not tint of it's icons. So there will be white status bar with white icons and text on it(case I have at this moment). To turn on dark tint you have to use windowLightStatusBar (API 23) – Rustam Salakhutdinov Jul 24 '16 at 16:23
  • You're going to have to show some screenshots because afaik what you ask is not possible by standard means. – Eugen Pechanec Jul 24 '16 at 17:18
  • @EugenPechanec . Add pictures to make it more clear. – Rustam Salakhutdinov Jul 24 '16 at 17:38
  • 1
    A standard way would be to compile against the [Android SDK extension] provided by your phone's vendor. And that would limit your app only to devices which have that SDK extension. You'll probably want to focus on more important issues than this. – Eugen Pechanec Jul 24 '16 at 17:43

3 Answers3

-1

For API level < 23, Add this to your activity for dark icons on a light background:

Window window = this.getWindow();
View view = window.getDecorView();
setLightStatusBar(view, this);

Then create a function setLightStatusBar that will show dark icons on a light background:

public static void setLightStatusBar(View view, Activity activity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

            int flags = view.getSystemUiVisibility();
            flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
            view.setSystemUiVisibility(flags);

            // You can change the background color of the status bar here
            activity.getWindow().setStatusBarColor(Color.WHITE);
        }
    }

For API level 23 and above, simply add this to your styles

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:windowLightStatusBar">true</item>
        <item name="android:statusBarColor">@android:color/white</item>
    </style>

</resources>
-2

You can use this method to give a statusBar your own color in kitkat and lollipop and above devices

public void translucentStatusBar() {

            if(Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                        WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
                getWindow().setStatusBarColor(Color.TRANSPARENT);
            }

            View view = findViewById(R.id.vFakeStatusBar);
            view.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
                    (int) getResources().getDimension(R.dimen.default_status_bar_height)));
        }

In above code snippet view in the statusBar of height 24dp(default).

-3

From this answer, add in values-v23/style.xml

<item name="android:windowLightStatusBar">true</item>

Hope it helped

Community
  • 1
  • 1
Rick
  • 3,943
  • 6
  • 33
  • 45