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.