1, the background running a service interval 5s from the server to get data once, according to business needs, when the need to remind users, from the right to automatically underline
A similar effect is as follows: Notification pop-up on any interface
2. Realization Process
The root layout of the ①android is called Dector (obtained by: Window.getdecotrview ()),
② in activity Setcontview set the activity layout, can be Dector.getchildat (0)
③ Customize a framlayout,framlayout First add above, customize the notification content, add to Framlayout, and then add our custom framelayout to Dector
For example:
1ViewGroup Decor =(ViewGroup) Mwindow.getdecorview ();//Get root layout2ViewGroup above = (viewgroup) decor.getchildat (0);//Get the layout of the activity3 Decor.removeview (above);4 above.setbackgrounddrawable (Decor.getbackground ());5/** Custom Notification Start **/6Layoutinflater Inflater =(Layoutinflater) Context.getsystemservice (context.layout_inflater_service);7 8Relativelayout.layoutparams LP =Newrelativelayout.layoutparams (ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);9 RLNOTIFACTIONS.SETLAYOUTPARAMS (LP);Ten OneView Grid = Inflater.inflate (R.layout.listview_notification,NULL); AListView ListView =(ListView) Grid.findviewbyid (r.id.listview_notification_list); - Listview.setadapter (adapter); -Relativelayout.layoutparams LPTV =NewRelativelayout.layoutparams (790, ViewGroup.LayoutParams.MATCH_PARENT); theLptv.addrule (relativelayout.align_parent_top|relativelayout.align_parent_right); -Lptv.setmargins (0, 100, 0, 0);
/** end of custom notification **/ - Rlnotifactions.addview (GRID,LPTV); - + Maboveview.addview (above);
A AddView (maboveview); at AddView (rlnotifactions); -Decor.addview ( This//this refers to the custom framelayout mentioned above -}
Reference:
Https://github.com/adamrocker/simple-side-drawer/blob/master/doc/simple_side_drawer2.pdf
Https://github.com/adamrocker/simple-side-drawer
57. How to implement global notification in Android app