To do this, you will need the permission " android.permission.SYSTEM_ALERT_WINDOW ". After adding permission to the manifest file, do the following:
final WindowManager.LayoutParams param=new WindowManager.LayoutParams(); param.flags=WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; final View view=findViewById(R.id.my_floating_view); final ViewGroup parent=(ViewGroup)view.getParent(); parent.removeView(view); param.format=PixelFormat.RGBA_8888; param.type=WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; param.gravity=Gravity.TOP|Gravity.LEFT; param.width=view.getLayoutParams().width; param.height=view.getLayoutParams().height; final WindowManager wmgr=(WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE); wmgr.addView(view,param);
In addition, I believe that this is the way Facebook chat chapters are done. Hope this helps!
source share