Android wants to determine whether Activity is full screen. I found some methods online and saw that it was not useful to directly obtain flags and compare a specific value. In fact, after analysis, I think it should be wrong. Most of them are how to set and cancel full screen, and there is no way to determine whether full screen is full screen.
In fact, full screen control is either set through the theme or the code addFlags, and eventually it will go to the Window's setFlags method. Let's see the source code below:
public void setFlags(int flags, int mask) { final attrs = getAttributes(); = (&~mask) | (flags&mask); mForcedWindowFlags |= mask; dispatchWindowAttributesChanged(attrs); }
The main logic is this sentence:
= (&~mask) | (flags&mask)
It is a bit operation, take a look at the flag constants that can be set in attrs
public static final int FLAG_ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001; public static final int FLAG_DIM_BEHIND = 0x00000002; public static final int FLAG_BLUR_BEHIND = 0x00000004; public static final int FLAG_NOT_FOCUSABLE = 0x00000008; public static final int FLAG_NOT_TOUCHABLE = 0x00000010; public static final int FLAG_NOT_TOUCH_MODAL = 0x00000020; public static final int FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040; public static final int FLAG_KEEP_SCREEN_ON = 0x00000080; public static final int FLAG_LAYOUT_IN_SCREEN = 0x00000100; public static final int FLAG_LAYOUT_NO_LIMITS = 0x00000200; public static final int FLAG_FULLSCREEN = 0x00000400; public static final int FLAG_FORCE_NOT_FULLSCREEN = 0x00000800; public static final int FLAG_DITHER = 0x00001000; public static final int FLAG_SECURE = 0x00002000; public static final int FLAG_SCALED = 0x00004000; public static final int FLAG_IGNORE_CHEEK_PRESSES = 0x00008000; public static final int FLAG_LAYOUT_INSET_DECOR = 0x00010000; public static final int FLAG_ALT_FOCUSABLE_IM = 0x00020000; public static final int FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000; public static final int FLAG_SHOW_WHEN_LOCKED = 0x00080000; public static final int FLAG_SHOW_WALLPAPER = 0x00100000; public static final int FLAG_TURN_SCREEN_ON = 0x00200000; public static final int FLAG_DISMISS_KEYGUARD = 0x00400000; public static final int FLAG_SPLIT_TOUCH = 0x00800000; public static final int FLAG_HARDWARE_ACCELERATED = 0x01000000; public static final int FLAG_LAYOUT_IN_OVERSCAN = 0x02000000; public static final int FLAG_TRANSLUCENT_STATUS = 0x04000000; public static final int FLAG_TRANSLUCENT_NAVIGATION = 0x08000000; public static final int FLAG_LOCAL_FOCUS_MODE = 0x10000000; public static final int FLAG_SLIPPERY = 0x20000000; public static final int FLAG_LAYOUT_ATTACHED_IN_DECOR = 0x40000000; public static final int FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS = 0x80000000;
It is obvious that if these hexadecimal values are replaced by binary, there is only one 1, and 1 of each variable is in a different position, so setting a flag is definitely to set the corresponding position of flags to 1, and clearFlags is to set the corresponding position to 0.
For example, the value of FLAG_FULLSCREEN is 0x00000400. If it is replaced with binary, the following bit is 0100 0000 0000, which controls the 11th bit from right to left. When addFlags, the two parameters flags are the same as mask. Therefore, the flags&mask of (&~mask) | (flags&mask) performs the operation with oneself, but the result is still itself. When the end of ~mask is 1011 11111, and when the original flags is 1, the 11th bit will definitely become 0, and the other bits are combined with 1, and the other bits are still used as they are, and then the 11th bit will become 1 again. Moreover, this operation will only affect the 11th bit, and the other position will remain unchanged. Regardless of whether the original 11th bit is 0 or 1, the result will become 1.
Similarly, if it is clearFlags, the first parameter becomes 0, and the second parameter is FLAG_FULLSCREEN. In this way, (flags&mask) must be 0, only look at the previous one, the 11th bit of the (&~mask) operation must be 0.
In fact, (&~mask) | (flags&mask) The previous AND operation will turn the corresponding position into 0, and then look at the subsequent AND operation. The subsequent calculation result will be 1, which will eventually be 1, and the subsequent calculation will be 0, which will eventually be 0. The subsequent control is 0 or to do a calculation with yourself.
I said a lot of nonsense, but it is actually the most basic bit operation. Then it is very simple to determine whether the full screen is full. Just look at whether the 11th bit of flags is 0 or 1 from right to left. Just do a logical reconciliation with FLAG_FULLSCREEN. Except for the 11th bit, the other bits become 0.
The judgment method is:
if ( (getWindow().getAttributes().flags & .FLAG_FULLSCREEN) == .FLAG_FULLSCREEN) { // It's full screen}
It's over here.
The above is the detailed content of how Android determines whether the page is full-screen. For more information on whether the page is full-screen on Android, please follow my other related articles!