Get active flags on Android Window
Asked Answered
P

1

29

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

Pucka answered 13/6, 2014 at 20:11 Comment(0)
L
78

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) ...
Leveridge answered 13/6, 2014 at 21:45 Comment(2)
yeah but it return me an int that doen't concern nthing... :SPucka
@Pucka the int contains all your flags. you just need bitwise operation to extract them. Edited the answer, check the example.Leveridge

© 2022 - 2024 — McMap. All rights reserved.