1

我正在从手表发送通知,并且我希望通知是可点击的,即点击时它会打开一个活动。这是它的样子

通知
(来源:macnn.com

但是,我不想显示播放图标,只想要简单的通知外观。即使我设置了一个空的操作图标,图标空间仍然被占用,我无法将文本放入该空间。有没有办法释放图标空间以显示文本?

代码如下:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("Tracking")
            .setContentText("Tap to open.")
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.launchbg))
            .setLocalOnly(true)
            .addAction(R.drawable.empty_icon, "blah", pendingSaveIntent)                 
            .extend(new NotificationCompat.WearableExtender()
                    .setContentAction(0));
4

2 回答 2

1

setHintHideIcon(true)隐藏图标。

NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher)
        .setContentTitle("Tracking")
        .setContentText("Tap to open.")
        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.launchbg))
        .setLocalOnly(true)
        .addAction(R.drawable.empty_icon, "blah", pendingSaveIntent)                 
        .extend(new NotificationCompat.WearableExtender()
                .setHintHideIcon(true)
                .setContentAction(0));
于 2015-01-17T20:51:07.117 回答
0

为了实现这一点,您必须创建一个自定义 RemotViews 对象并通过以下方式将自定义布局传递给通知:

RemoteViews remoteView = new RemoteViews("PACKAGENAMEWHERELAYOUTEXISTS", R.layout.custom_layout);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                         .setContent(remoteView);

看:

http://developer.android.com/reference/android/widget/RemoteViews.html#RemoteViews(java.lang.String,int)

用于远程视图。

和设置内容:

http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setContent(android.widget.RemoteViews)

于 2015-01-17T00:54:27.403 回答