Android 11 PopupWindow 內(nèi)容區(qū)域會(huì)被 導(dǎo)航欄 遮擋,可以利用 FLAG_LAYOUT_IN_SCREEN 的 Flag 進(jìn)行校正,如下:
private fun setLayoutInScreenEnabled(popup: PopupWindow) {
// 修復(fù)安卓11導(dǎo)航欄遮擋問題
if (Build.VERSION.SDK_INT > BUILD_VERSION_CODE_Q) {
val wm = context.getSystemService(Context.WINDOW_SERVICE) as? WindowManager
var viewContent = popup.contentView
while (viewContent != null && viewContent.layoutParams !is WindowManager.LayoutParams) {
viewContent = viewContent.parent as? View
}
if (viewContent?.layoutParams is WindowManager.LayoutParams) {
val params = viewContent.layoutParams as WindowManager.LayoutParams
params.flags = params.flags or WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
wm?.updateViewLayout(viewContent, params)
}
}
}