小编典典
可以通过创建一个Service在当前视图中添加视图的方法来做到这一点WindowManager:
public class OverlayService extends Service {
@Override
public void onCreate() {
super.onCreate();
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
View overlay = /* create your overlay here */;
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
PixelFormat.TRANSLUCENT);
windowManager.addView(overlay , params);
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
但是您需要以下额外权限:
然后只需在清单中注册服务:
并启动它:
startService(new Intent(this, OverlayService.class));
-06-07