【问题标题】:Android wear - Notification - Image Span is not workingAndroid 磨损 - 通知 - 图像跨度不起作用
【发布时间】:2015-01-15 07:18:09
【问题描述】:

我在 Android 磨损通知中使用 ImageSpan 来设置通知样式,但它不起作用。请告诉我如何在通知中使用 ImageSpan 的过程,感谢您的帮助。以下是我正在使用的示例代码。

SpannableStringBuilder 标题 = new SpannableStringBuilder();

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

提前致谢。

【问题讨论】:

  • 是的,imagespan 目前无法在通知中工作,我得到的官方回复是谷歌设计的。

标签: android notifications android-notifications wear-os


【解决方案1】:

您不能在通知中使用 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 作为标题文本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多