Android ApiDemos example (29): App-& gt; Notification-& gt; St

Source: Internet
Author: User

In this example, Icons Only and Icons and marquee have nothing to note.

The Use Remote views in balloon introduces the Layout that can be customized to display Notification in the Extended Status bar. The Extended Status Bar displays Notification as an icon by default, followed by text, which is sufficient in most cases. If needed, you can also use the custom Layout to display the Notification in the Extented Status bar by using RemoteView:

[Java]
Private void setMoodView (int moodId, int textId ){

Notification notif = new Notification ();

Notif. contentIntent = makeMoodIntent (moodId );

CharSequence text = getText (textId );
Notif. tickerText = text;

// The icon for the status bar
Notif. icon = moodId;

// Our custom view
RemoteViews contentView = new RemoteViews (getPackageName (),
R. layout. status_bar_balloon );
ContentView. setTextViewText (R. id. text, text );
ContentView. setImageViewResource (R. id. icon, moodId );
ContentView. setImageViewResource (R. id. icon1, moodId );
Notif. contentView = contentView;

MNotificationManager. Policy (R. layout. status_bar_configurations,
Notif );
}
Private void setMoodView (int moodId, int textId ){
 
Notification notif = new Notification ();
 
Notif. contentIntent = makeMoodIntent (moodId );
 
CharSequence text = getText (textId );
Notif. tickerText = text;
 
// The icon for the status bar
Notif. icon = moodId;
 
// Our custom view
RemoteViews contentView = new RemoteViews (getPackageName (),
R. layout. status_bar_balloon );
ContentView. setTextViewText (R. id. text, text );
ContentView. setImageViewResource (R. id. icon, moodId );
ContentView. setImageViewResource (R. id. icon1, moodId );
Notif. contentView = contentView;
 
MNotificationManager. Policy (R. layout. status_bar_configurations,
Notif );
}

In order to be different from the default Status Bar Layout, we add an ImageView in/res/status_bar_balloon.xml: each icon is displayed on the left and right, with text in the middle.

<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "horizontal"
Android: baselineAligned = "false"
Android: gravity = "center_vertical"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content">

<ImageView android: id = "@ + id/icon"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_marginRight = "10dip"/>
<TextView android: id = "@ + id/text"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: textColor = "# ffffffff"/>
<ImageView android: id = "@ + id/icon1 ″
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_marginRight = "10dip"/>

</LinearLayout>

 

Use default values where applicable describes how to Use the default sound, vibrate, or both:

 

[Java]
Int default = Notification. DEFAULT_SOUND;
// Notification. DEFAULT_SOUND
// Notification. DEFAULT_VIBRATE
// Notification. DEFAULT_ALL

Notification. defaults = defaults;
Int default = Notification. DEFAULT_SOUND;
// Notification. DEFAULT_SOUND
// Notification. DEFAULT_VIBRATE
// Notification. DEFAULT_ALL
 
Notification. defaults = defaults;

Author: mapdigit
 

 

Related Article

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.