Adding Pages to a Notification给通知添加页面
When you'd like to provide more information without requiring users to open your app on their handheld device, you can add one or more pages to the notification on Android Wear. The additional pages appear immediately to the right of the main notification card. For information about when to use and how to design multiple pages, see the Design Principles of Android Wear.
当你想提供更多的信息,而且不需要用户使用手持设备打开应用时,你可以在Android Wear上为通知添加一个或若干页面。附加的页面会在主通知卡片的右边立即显示出来。关于什么时候且如何设计多页面,请看 Design Principles of Android Wear。
When creating a notification with multiple pages, start by creating the main notification (the first page) the way you'd like the notification to appear on a phone or tablet. Then, add pages one at a time with the addPage()
method, or add multiple pages in a Collection
with the addPages()
method.
For example, here's some code that adds a second page to a notification:
当创建多条张页面时,把通知显示在手机或平板上是第一步,先创建一个主通知(第一张页面),然后,使用 addPage()方法每次添加一张页面,或者使用
addPages()方法从
Collection对象添加若干页面。
// 为主通知创建 builder
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.new_message)
.setContentTitle("Page 1")
.setContentText("Short message")
.setContentIntent(viewPendingIntent);
// 为第二张页面创建big text风格
BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle();
secondPageStyle.setBigContentTitle("Page 2")
.bigText("A lot of text...");
// Create second page notification
Notification secondPageNotification =
new NotificationCompat.Builder(this)
.setStyle(secondPageStyle)
.build();
// Create main notification and add the second page
Notification twoPageNotification =
new WearableNotifications.Builder(notificationBuilder)
.addPage(secondPageNotification)
.build();