Android: How to draw free on top of anything (any activity)

后端 未结 2 886
不知归路
不知归路 2021-01-30 23:16

How do you draw a view on top of all other activities regardless of what they are showing and without using transparent activities or consuming its touch events.

Its lik

相关标签:
2条回答
  • 2021-01-30 23:35

    Take a look at this cool article, I think that's exactly what you want :

    http://www.piwai.info/chatheads-basics

    In short : you want to add this permission to your manifest :

    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    

    For api >= 23, you'll need to request the runtime permission Settings.ACTION_MANAGE_OVERLAY_PERMISSION

    Then in a service, get the window manager

    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    

    and add your views with the addView method

    0 讨论(0)
  • 2021-01-30 23:45

    Take a look at WindowManager. You can do something like (WindowManager)mContext.getSystemService("window"); if you want to get the root view and use the method addView(view, params) if you want to add a view.

    0 讨论(0)
提交回复
热议问题