Get WindowManager Object
WindowManager wm = (WindowManager) getapplicationcontext (). Getsystemservice (Window_service);
Initialize the view that the desktop needs to display
View view = Layoutinflater.from (context). Inflate (r.layout.message_item_im_left, NULL);
Get Layoutparams Object Settings view on the desktop display style
Windowmanager.layoutparams params = new Windowmanager.layoutparams ();
Params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
Params.flags = Layoutparams.flag_not_touch_modal | layoutparams.flag_not_focusable;
Set the width height of the view
Params.width = WindowManager.LayoutParams.FILL_PARENT;
Params.height = WindowManager.LayoutParams.WRAP_CONTENT;
Set transparency
Params.alpha = 80;
Params.gravity=gravity.left| Gravity.top;
Set X, y initial values as the origin in the upper-left corner of the screen
params.x = 0;
Params.y = 0;
Add a view to the desktop display
Wm.addview (view, params);
Permissions required to open
<uses-permission android:name= "Android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name= "Android.permission.INTERNAL_SYSTEM_WINDOW"/>