How to implement a popup overlay that can be displayed over any other app in Android

前端 未结 5 916
花落未央
花落未央 2020-12-12 15:37

How can I implement a popup overlay for an app that can be displayed over any other app.

Facebook implemented a very similar feature called Chatheads in its new Fac

5条回答
  •  没有蜡笔的小新
    2020-12-12 16:35

    Every Activity, dialog as well as service is attached with a window. Facebook keeps a service running in background and in the service they fetch window manager object by

    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

    Create Layout Params needed while adding your view

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_PHONE,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
        PixelFormat.TRANSLUCENT);
    

    now add your view to window manager by following method

    windowManager.addView(yourView, params);
    

提交回复
热议问题