gpt4 book ai didi

java - 使用 WindowManager 覆盖页脚

转载 作者:行者123 更新时间:2023-12-02 09:23:39 30 4
gpt4 key购买 nike

我正在尝试使用 WindowManager 覆盖屏幕,它运行良好,但覆盖屏幕不会覆盖页脚,而是覆盖标题。 screenshot

这是我的代码。

wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);

overlayView_bg = new View(getApplicationContext());
// making service view fullscreen
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH ,
PixelFormat.TRANSLUCENT);
wm.addView(overlayView_bg, params);

请帮我处理重叠页脚。谢谢!

最佳答案

我自己找到了解决方案。

        int navigationHeight = 0, statusHeight = 0;
Resources resources = getApplicationContext().getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
navigationHeight= resources.getDimensionPixelSize(resourceId);
}
resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusHeight = resources.getDimensionPixelSize(resourceId);
}
DisplayMetrics displayMetrics = getApplicationContext().getResources().getDisplayMetrics();
float dpHeight = displayMetrics.heightPixels ;

// making service view fullscreen
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
-1,(int)(dpHeight + navigationHeight + statusHeight),0,-navigationHeight,
LAYOUT_FLAG,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR|
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.BOTTOM | Gravity.LEFT;
wm.addView(overlayView_bg, params);

运行良好。

关于java - 使用 WindowManager 覆盖页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58494801/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com