Android 如何在一个Service中拉起一个WindowManager窗口
时间: 2023-06-06 17:09:11 浏览: 120
这个问题属于技术问题,可以回答。在一个Service中拉起一个WindowManager窗口的方式是通过创建一个WindowManager.LayoutParams对象来设置窗口的一些属性,然后再通过WindowManager.addView()方法将其添加到WindowManager中。具体实现的代码如下:
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.CENTER;
params.x = 0;
params.y = 0;
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.MATCH_PARENT;
View view = LayoutInflater.from(this).inflate(R.layout.view_layout, null);
wm.addView(view, params);
阅读全文