Windowmanager.layoutparams:
int type_system_alert window Type:system window, such as Low power alert. (System form, such as lower battery warning prompt box)
int type_system_overlay Window type:system OVERLAY windows, which need to being displayed on top of everything Els E. (System overlay form, which needs to be displayed in the top)
The difference between Type_system_alert and Type_system_overlay
System_alert window can get focus, response action
When the System_overlay window is displayed, the focus is on the activity behind, and you can still manipulate the activity behind it.
The appropriate permission is required in the manifest file manifest
<uses-permission android:name= "Android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name= "Android.permission.SYSTEM_OVERLAY_WINDOW"/>
The following two ways of displaying windows do not fire the OnPause () event of the current activity.
1. seivece Create a form
1 Private voidShowsystemdialog () {2 /*Create UI Dialog*/ 3View v = view.inflate (Mcontext, R.layout.serveice_dialog,NULL); 4Alertdialog.builder Alertdialog =NewAlertdialog.builder (Mcontext); 5 Alertdialog.setview (v); 6Dialog =alertdialog.create (); 7 Dialog.getwindow (). SetType (WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); 8 //Dialog.getwindow (). SetType (WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY); 9 dialog.show (); Ten Note dialog After the Show method is executed, you can adjust the size of the dialog and update the data * * * * One /*set Size & POS*/ AWindowmanager.layoutparams LP =Dialog.getwindow (). GetAttributes (); -WindowManager WM =(WindowManager) Getsystemservice (Window_service); -Display display =Wm.getdefaultdisplay (); the if(Display.getheight () >display.getwidth ()) { - //lp.height = (int) (Display.getheight () * 0.5); -Lp.width = (int) (Display.getwidth () * 1.0); -}Else { + //lp.height = (int) (Display.getheight () * 0.75); -Lp.width = (int) (Display.getwidth () * 0.5); + } A D.getwindow (). SetAttributes (LP); at - /*Update UI Data*/ -LV =(ListView) D.getwindow (). Findviewbyid (R.id.listview); -Simpleadapter adapter =NewSimpleadapter (Mcontext, Getlistdata (), R.layout.list_item, - Newstring[]{"Item_text", "item_img"}, - New int[]{r.id.item_text, r.id.item_img}]; in Lv.setadapter (adapter); - to /*Set Listener*/ +Lv.setonitemclicklistener (NewOnitemclicklistener () { - Public voidOnitemclick (adapterview<?> Parent, view view,intPos, the LongID) { * D.dismiss (); $ } Panax Notoginseng }); - the}
2. Directly use Windowmanager.addview () to display the window directly in the background
1Layoutinflater Inflater =(Layoutinflater) Getsystemservice (context.layout_inflater_service);2Mdesktoplayout = Inflater.inflate (R.layout.volume_panel,NULL);3 //Get System Form4Mwindowmanager =(WindowManager) Getapplicationcontext (). Getsystemservice (Window_service);5 //layout styles for forms6Mlayoutparams =Newwindowmanager.layoutparams ();7 //Set the form display Type ――type_system_alert (System tip)8Mlayoutparams.type =WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;9 //set the form focus and touch:Ten //flag_not_focusable (Cannot get key input focus) OneMlayoutparams.flags =WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; A //Set the display mode -Mlayoutparams.format =pixelformat.rgba_8888; - //to set the alignment method themlayoutparams.gravity = Gravity.top |Gravity.left; - //Set form width and height -Mlayoutparams.width =WindowManager.LayoutParams.WRAP_CONTENT; -Mlayoutparams.height =WindowManager.LayoutParams.WRAP_CONTENT; + //set the position of the form to display otherwise in the center of the screen -Mlayoutparams.x = 50; +Mlayoutparams.y = 50; AMwindowmanager.addview (Mdesktoplayout, mlayoutparams);
Create window display in Android:service