Private voidshownotification () {//Message Notification Bar//define NotificationmanagerString NS =Context.notification_service; Notificationmanager Mnotificationmanager=(Notificationmanager) getsystemservice (NS); //Define the content information displayed in the notification bar inticon =R.drawable.ic_launcher; Charsequence Tickertext= "My Notification bar title"; Longwhen =System.currenttimemillis (); Notification Notification=NewNotification (icon, Tickertext, when); //define the content information to be displayed when the drop-down notification barContext context =Getapplicationcontext (); Charsequence Contenttitle= "My Notification bar label expanded title"; Charsequence ContentText= "My notification bar expands details"; Intent notificationintent=NewIntent ( This, Mainactivity.class); Pendingintent contentintent= Pendingintent.getactivity ( This, 0, notificationintent, 0); Notification.setlatesteventinfo (context, Contenttitle, ContentText, contentintent); //notifies the user to generate a title bar message notification using the Mnotificationmanager notify methodMnotificationmanager.notify (1, notification); }
Private voidshownotification () {notificationmanager nm=(Notificationmanager) Getsystemservice (Notification_service); Intent Intent=NewIntent ( This, Mainactivity.class); Pendingintent PD= Pendingintent.getactivity (mainactivity. This, 0, intent, 0); //Customize the drop-down view, such as the progress bar shown when downloading the software. Notification Notification =NewNotification (); Notification.icon=R.drawable.ic_launcher; Notification.tickertext= "custom!"; Remoteviews Contentview=Newremoteviews (Getpackagename (), R.layout.notify_view); Contentview.setimageviewresource (R.id.imageview_icon, R.drawable.ic_launcher); Contentview.settextviewtext (R.id.textview_title,"Hubei news broadcast"); Contentview.settextviewtext (R.id.textview_msg,"In Play"); Notification.contentview=Contentview; //you do not need to call the Setlatesteventinfo () method when using a custom drop -down view//However, you must define ContentintentNotification.contentintent =PD; Nm.notify (3, notification); //nm.cancel (ID);}
<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Match_parent"android:gravity= "Center_vertical"android:orientation= "Horizontal"android:padding= "3DP" > <ImageViewAndroid:id= "@+id/imageview_icon"Android:layout_width= "Wrap_content"Android:layout_height= "Match_parent"android:layout_centervertical= "true"Android:layout_marginright= "10DP" /> <RelativelayoutAndroid:id= "@+id/relativelayout_msg"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_centervertical= "true"Android:layout_marginleft= "10DP"Android:layout_torightof= "@+id/imageview_icon" > <TextViewAndroid:id= "@+id/textview_title"Android:layout_width= "100DP"Android:layout_height= "Wrap_content"Android:textcolor= "#FFF" /> <TextViewAndroid:id= "@+id/textview_msg"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_below= "@+id/textview_title" /> </Relativelayout> <ImageButtonAndroid:id= "@+id/button_notification_play"Android:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:layout_alignparentright= "true"android:layout_centervertical= "true"Android:background= "@color/transparent"android:src= "@drawable/play" /></Relativelayout>
Android Notification Notification Bar