我在 Android 穿戴通知中使用 ImageSpan 来设置通知样式,但它不起作用。请告诉我如何在通知中使用 ImageSpan 的过程,感谢任何帮助。按照我正在使用的示例代码。
SpannableStringBuilder title = new SpannableStringBuilder();
title.setSpan(new ImageSpan(context, bmp, ImageSpan.ALIGN_BASELINE),title.length()+2,title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
提前致谢。
最佳答案
您不能在 Notification 中使用 ImageSpan。
如果你想显示图片,有两种方法可以做到。
<强>1。自定义通知
这是一个代码 fragment
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 数据
代码 fragment
String originalStr = "emoji-" + newString(0x1f602) +newString(0x1f684)+"--over";
public static final String newString(int codePoint) {
return new String(Character.toChars(codePoint));
}
关于Android wear - 通知 - 图像跨度不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27958429/