首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我们能为android穿戴项目的通知做一个定制的布局吗?

我们能为android穿戴项目的通知做一个定制的布局吗?
EN

Stack Overflow用户
提问于 2014-07-24 11:19:13
回答 1查看 3.5K关注 0票数 2

我已经为android穿戴设备创建了一个项目。我需要定制可穿戴设备上的通知样式。有什么方法吗。

我的方法是

代码语言:javascript
复制
Intent displayIntent = new Intent(getApplicationContext(), CustomNotification.class);
 PendingIntent displayPendingIntent = PendingIntent.getActivity(getApplicationContext(),
         0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    Notification notification =
            new NotificationCompat.Builder(context)
                    .extend(new WearableExtender()
                            .setDisplayIntent(displayPendingIntent))
                            .build();

    int notificationId = 001;

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager =
            NotificationManagerCompat.from(this);

    notificationManager.notify(notificationId , notification);

但我没收到通知。

是否有任何方法可自定义我的自定义布局设计?

这是最明显的部分

代码语言:javascript
复制
 <activity android:name="com.client.android.CustomNotification"
     android:exported="true"
     android:allowEmbedded="true"
     android:taskAffinity=""
     android:theme="@android:style/Theme.DeviceDefault.Light" />
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-24 11:39:51

请查看有关在Android磨损上创建自定义通知的官方文档。

使用大视图:

可以将样式应用于通知程序,如BigPictureStyleBigTextStyleInboxStyle

下面是一个使用BigTextStyle的示例

代码语言:javascript
复制
// Specify the 'big view' content to display the long
// event description that may not fit the normal content text.
BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
bigStyle.bigText(eventDescription);

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.ic_event)
    .setLargeIcon(BitmapFractory.decodeResource(getResources(), R.drawable.notif_background))
    .setContentTitle(eventTitle)
    .setContentText(eventLocation)
    .setContentIntent(viewPendingIntent)
    .addAction(R.drawable.ic_map, getString(R.string.map), mapPendingIntent)
    .setStyle(bigStyle);

更多信息:

http://developer.android.com/training/wearables/notifications/creating.html#BigView

使用自定义通知布局:

您可以在Activity中创建布局,并将其嵌入通知:https://developer.android.com/training/wearables/apps/layouts.html#CustomNotifications中。

注意:请注意,这种方法有一些限制,只适用于直接从安卓穿戴设备(而不是从电话)提交的通知。

请阅读本教程末尾的说明:

Note:当通知在主屏幕上查看时,系统会用它从通知的语义数据生成的标准模板显示它。这个模板在所有的观察面上都能很好地工作。当用户滑动通知时,他们将看到通知的自定义活动。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24932243

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档