通知徽章传达特定应用的摘要或状态信息。 它们可以是数字(1-99)或一组系统提供的标志符号之一。 最好通过徽章传达的信息示例包括在线游戏中的网络连接状态、消息应用中的用户状态、邮件应用中的未读邮件数以及社交媒体应用中的新帖子数。
无论应用是否正在运行,通知徽章都会显示在应用的任务栏图标上及其开始屏幕磁贴的右下角。 徽章可以显示在所有磁贴大小上。
Note
无法提供自己的锁屏提醒图像;只能使用系统提供的锁屏提醒图像。
Numeric badges
| Value | Badge | XML |
|---|---|---|
| 从 1 到 99 的数字。 值 0 等效于字形值“无”,并将清除徽章。 |
|
<badge value="1"/> |
| 任何大于 99 的数字。 |
|
<badge value="100"/> |
Glyph badges
徽章可以显示一组不可扩展的状态图标,而不是数字。
| Status | Glyph | XML |
|---|---|---|
| none | (未显示徽章。) | <badge value="none"/> |
| 活动 | 用于标识“活动”状态的徽章。 | <badge value="activity"/> |
| alarm |
|
<badge value="alarm"/> |
| 警报 |
|
<badge value="alert"/> |
| attention |
|
<badge value="attention"/> |
| available |
|
<badge value="available"/> |
| away |
|
<badge value="away"/> |
| busy |
|
<badge value="busy"/> |
| 错误 |
|
<badge value="error"/> |
| newMessage | 表示“newMessage”状态的图标徽章。 | <badge value="newMessage"/> |
| paused |
|
<badge value="paused"/> |
| playing |
|
<badge value="playing"/> |
| unavailable |
|
<badge value="unavailable"/> |
创建徽章
这些示例展示如何进行徽章更新。
创建数字徽章
private void setBadgeNumber(int num)
{
// Get the blank badge XML payload for a badge number
XmlDocument badgeXml =
BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeNumber);
// Set the value of the badge in the XML to our number
XmlElement badgeElement = badgeXml.SelectSingleNode("/badge") as XmlElement;
badgeElement.SetAttribute("value", num.ToString());
// Create the badge notification
BadgeNotification badge = new BadgeNotification(badgeXml);
// Create the badge updater for the application
BadgeUpdater badgeUpdater =
BadgeUpdateManager.CreateBadgeUpdaterForApplication();
// And update the badge
badgeUpdater.Update(badge);
}
创建字形徽章
private void updateBadgeGlyph()
{
string badgeGlyphValue = "alert";
// Get the blank badge XML payload for a badge glyph
XmlDocument badgeXml =
BadgeUpdateManager.GetTemplateContent(BadgeTemplateType.BadgeGlyph);
// Set the value of the badge in the XML to our glyph value
Windows.Data.Xml.Dom.XmlElement badgeElement =
badgeXml.SelectSingleNode("/badge") as Windows.Data.Xml.Dom.XmlElement;
badgeElement.SetAttribute("value", badgeGlyphValue);
// Create the badge notification
BadgeNotification badge = new BadgeNotification(badgeXml);
// Create the badge updater for the application
BadgeUpdater badgeUpdater =
BadgeUpdateManager.CreateBadgeUpdaterForApplication();
// And update the badge
badgeUpdater.Update(badge);
}
清除徽章
private void clearBadge()
{
BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear();
}
获取示例代码
-
Notifications sample
演示如何创建动态磁贴、发送徽章更新和显示 Toast 通知。