Search code examples
androiduser-interfacewindowmaterial-design

How do you get the "dim amount" of a Window?


Android has a Window class that lets us set the dim amount behind the window.

public void setDimAmount (float amount)

While there is the "set" function, there isn't a "get" function for checking the existing dim amount.

Could someone let me know how I can "get" or find out the existing or default dim amount?


Solution

  • WindowManager.LayoutParams holds the attributes for window . A quick loop up at source code could help.

     public void setDimAmount(float amount) {
        final WindowManager.LayoutParams attrs = getAttributes();
        attrs.dimAmount = amount;
        mHaveDimAmount = true;
        dispatchWindowAttributesChanged(attrs);
    }
    

    So when you want to get the dimAmount you can just get it from WindowManager.LayoutParams.

    float dimAmount = getWindow().getAttributes().dimAmount;