Android Wear - 通知 - 图片跨度不起作用

3

我正在使用Android Wear通知中的ImageSpan进行样式设置,但它不起作用。请告诉我如何在通知中使用ImageSpan的步骤,任何帮助都将不胜感激。以下是我正在使用的示例代码。

SpannableStringBuilder title = new SpannableStringBuilder();

title.setSpan(new ImageSpan(context, bmp, ImageSpan.ALIGN_BASELINE),title.length()+2,title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

提前感谢您的帮助。


是的,目前 Imagespan 在通知中无法工作,我得到的官方回复是谷歌设计成这样。 - Jimmy Chen
1个回答

6

你不能在通知中使用ImageSpan。


如果您想显示图像,有两种方法可以做到。
1. 自定义通知 这是一段代码片段:

      RemoteViews contentViews = new RemoteViews(context.getPackageName(), R.layout.view_notice_common);
        SimpleDateFormat fmt = new SimpleDateFormat("HH:mm");
        contentViews.setTextViewText(R.id.notice_time, fmt.format(Calendar.getInstance().getTime()));
        contentViews.setTextViewText(R.id.notice_title, title);
        contentViews.setTextViewText(R.id.notice_extend_message, content);
        Bitmap smallBitmap = bundle.getParcelable("APP_ICON");
        if (smallBitmap != null) {
            contentViews.setImageViewBitmap(R.id.notice_drawable, smallBitmap);
        } else {
            contentViews.setImageViewResource(R.id.notice_drawable, R.drawable.icon);
        }
        notification.contentView = contentViews;

在此输入图片描述

2. 使用 Unicode 数据
代码片段

  String originalStr = "emoji-" + newString(0x1f602) +newString(0x1f684)+"--over";
  public static final String newString(int codePoint) {
     return new String(Character.toChars(codePoint));
}

然后将originalStr用作标题文本。
enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接