作者:亚璨的秘密 | 来源:互联网 | 2023-05-26 17:33
我在Android Wear通知中使用ImageSpan进行通知中的样式设置,但无法正常工作。如果有任何帮助,请告诉我该程序如何在通知中使用ImageSpan。以下示例代码我正在使用。
SpannableStringBuilder title =新的SpannableStringBuilder();
title.setSpan(新ImageSpan(上下文,bmp,ImageSpan.ALIGN_BASELINE),title.length()+ 2,title.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
提前致谢。
1> RxRead..:
您不能在Notification中使用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作为标题文本。