57. How to implement global notification in Android app

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.