编写:wangyachen - 原文:http://developer.android.com/training/wearables/notifications/pages.html
当开发者想要在不需要用户在他们的手机上打开app的情况下,还可以允许表达更多的信息,那么开发者可以在可穿戴设备上的Notification中添加一个或多个的页面。添加的页面会马上出现在主 Notification 卡片的右边。
为了创建一个拥有多个页面的 Notification,开发者需要:
举个例子,以下代码为Notification添加了第二个页面:
// Create builder for the main notification NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.new_message) .setContentTitle("Page 1") .setContentText("Short message") .setContentIntent(viewPendingIntent); // Create a big text style for the second page 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(); // Add second page with wearable extender and extend the main notification Notification twoPageNotification = new WearableExtender() .addPage(secondPageNotification) .extend(notificationBuilder) .build(); // Issue the notification notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(notificationId, twoPageNotification);
下一课:以Stack的方式显示Notifications
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8