Android implementation of custom status bar notifications (status Notification)

Source: Internet
Author: User

In the development of Android projects, sometimes in order to achieve better interaction with the user, in the notice bar this small corner, we usually need to enrich the content, this time we need to implement a custom notification bar, such as the following 360 or NetEase style:

The first thing we need to know is the type of control supported by the custom layout file: Notification's custom layout is remoteviews, so it only supports Framelayout, LinearLayout, Relativelayout three layout controls, while supporting AnalogClock, chronometer, Button, ImageButton, ImageView, ProgressBar, TextView, Viewflipper , ListView, GridView, StackView, and Adapterviewflipper these UI controls. For other unsupported controls, the ClassNotFoundException exception will be thrown when used.

At the same time, we also need to understand that notification supports intent types (all instances of the Pendingintent Class).

Here is the specific implementation: In this notification bar we put a progress bar

Get the Notification Manager    String ns = Context.notification_service;    Notificationmanager nm =     (notificationmanager) ctx.getsystemservice (NS);        Create Notification objectint icon = R.drawable.robot; Charsequence tickertext = "Hello"; long when = System.currenttimemillis (); Notification Notification = new Notification (icon, Tickertext, when);//set Contentview using Setlatesteveninfo    Intent Intent = new Intent (intent.action_view);    Intent.setdata (Uri.parse ("http://www.google.com"));    pendingintent pi = pendingintent.getactivity (ctx, 0, intent, 0);//    Notification.setlatesteventinfo (CTX, "title", " Text ", pi);//Use the default style    notification.contentintent = pi;    Notification.contentview = new Remoteviews (Ctx.getpackagename (), r.layout.noti);    Send notificationnm.notify (1, notification);

The effect of the implementation is as follows: (right is the system default style)


This is just a simple example, in order to achieve our own effect we just need to modify the layout file is OK.


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.