Vipin Dubey
Vipin Dubey

Reputation: 592

WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS not changing status bar color

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

Upvotes: 1

Views: 2515

Answers (3)

Darthcow
Darthcow

Reputation: 368

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>

Upvotes: 1

Rahul Gaur
Rahul Gaur

Reputation: 1689

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!

Upvotes: 0

Govind Prajapati
Govind Prajapati

Reputation: 206

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;
}

Upvotes: 0

Related Questions