1

i making a gallery aplication in android in which the image is in full screen. So it used below line

window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

Now this works fine , i mean the image is now full screen but problem arises when the image background is white as status bar icon color is white so its looks like there is no status bar .

To solve this i tries setting status bar color like this.

window.setStatusBarColor(Color.TRANSPARENT)

But this also not works . I have tried setting other values like.

 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)

But this also not works ! Can you please help me how can i make status bar color transparent while setting the

WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS

Thanks in advance

Vipin Dubey
  • 582
  • 1
  • 9
  • 26
  • setStatusBarColor does not affect the tint color of the status bar icons. You're looking for `View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR` – Tim Sep 17 '19 at 13:20
  • window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR this makes the status bar icon color but it does not makes background of status bar transparent or transluscent – Vipin Dubey Sep 17 '19 at 13:25
  • no but you already know how to do that – Tim Sep 17 '19 at 13:29
  • window.setStatusBarColor(Color.TRANSPARENT) this does not works ! Can u tell me the method to achieve what i want – Vipin Dubey Sep 17 '19 at 13:30
  • open google and search for "android transparent status bar" – Tim Sep 17 '19 at 13:32

3 Answers3

1

setting the flag to FLAG_LAYOUT_NO_LIMITS makes the status bar completely transparent and unable to have any color, remove those flags and then change the color.

EDIT: how I achieved what you want(that is the status bar to be inside the app and have a layer of some color and certain transparency):


  private fun changeStatusBarToOpaque() {
        with(window) {
            clearFlags(FLAG_LAYOUT_NO_LIMITS)
            clearFlags(TRANSLUCENT_STATUS)
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                statusBarColor = getCompatColor(R.color.opacityWhite)
                addFlags(FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
            }
        }
    }

and your theme should have these two tags

<item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
Darthcow
  • 358
  • 4
  • 14
  • also take a look at the question on: https://stackoverflow.com/questions/29311078/android-completely-transparent-status-bar – Darthcow Dec 30 '19 at 11:30
0

Try this in Activity before set content view

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setStatusBarColor(getFactorColor(getResources().getColor(R.color.action_bar_color), 0.4f));
}

where getFactorColor method is

public static int getFactorColor(int color, float factor) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= factor;
    color = Color.HSVToColor(hsv);
    return color;
}
Govind Prajapati
  • 208
  • 3
  • 10
0

Add this method

public static void setStatusBarColor(int color, Activity context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = context.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(context.getResources().getColor(color));
    }
}

and call it like Utilities.setStatusBarColor(R.color.someColor, context);

android have Transparent color Color.TRANSPARENT

or add this in your colors.xml

<color name="trans">#00FFFFFF</color>

hope this will help!

Rahul Gaur
  • 1,661
  • 1
  • 13
  • 29