Android implements its own definition status bar notification (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 their own definition of the notification bar, such as the following 360 or NetEase style:

The first thing we need to understand is that we define the type of control that the layout file supports: Notification's own definition layout is remoteviews, so it only supports Framelayout, LinearLayout, Relativelayout three layout controls, same time support 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 detailed 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);

Implemented effects such as: (Right-hand system default style)


This is just a simple demo example, in order to achieve our own effect we just need to change 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.