旧的FLAG_LAYOUT_INSET_DECOR、FLAG_LAYOUT_ATTACHED_IN_DECOR已经废弃,android R开始新的接口是android.view.WindowManager.LayoutParams#setFitInsetsTypes(接口如下):
static final int FIRST = 1 << 0;
static final int STATUS_BARS = FIRST;
static final int NAVIGATION_BARS = 1 << 1;
static final int CAPTION_BAR = 1 << 2;
static final int IME = 1 << 3;
static final int SYSTEM_GESTURES = 1 << 4;
static final int MANDATORY_SYSTEM_GESTURES = 1 << 5;
static final int TAPPABLE_ELEMENT = 1 << 6;
static final int DISPLAY_CUTOUT = 1 << 7;
static final int LAST = 1 << 8;
static final int SIZE = 9;
static final int WINDOW_DECOR = LAST;
/**
* Specifies types of insets that this window should avoid overlapping during layout.
*
* @param types which types of insets that this window should avoid. The initial value of
* this object includes all system bars.
*/
public void setFitInsetsTypes(@InsetsType int types) {
mFitInsetsTypes = types;
privateFlags |= PRIVATE_FLAG_FIT_INSETS_CONTROLLED;
}
windowManager.addView时LayoutParams的type用TYPE_APPLICATION_OVERLAY,并且加上
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
fitInsetsTypes = 0
}
//其他
//WindowInsets.Type.systemBars()
//WindowInsets.Type.navigationBars()
//WindowInsets.Type.statusBars()
即可实现悬浮窗扩展到状态栏或虚拟导航栏显示