Get active flags on Android Window

iGio90 picture iGio90 · Jun 13, 2014 · Viewed 10k times · Source

is it possible to get programmatically which flags are currently active on a Window?

We can enable flags with:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

Does api provides a way to get a list of currently active flags? Thanks

Answer

matiash picture matiash · Jun 13, 2014

You can use:

int flags = getWindow().getAttributes().flags;

You can see it's used by the Window.setFlags() implementation:

public void setFlags(int flags, int mask) {
    final WindowManager.LayoutParams attrs = getAttributes();
    attrs.flags = (attrs.flags&~mask) | (flags&mask);
    ...

To determine if individual flags are set, you must use bitwise and. For example:

if ((flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) != 0) ...