美文网首页
Android开发自定义通知栏内容显示表情

Android开发自定义通知栏内容显示表情

作者: 你的益达233 | 来源:发表于2021-05-19 18:25 被阅读0次

效果图:

通知栏表情.jpg

一、背景:项目中显示表情和文字是通过spannablestring显示,表情就用imagespan

二、在notification调试发现,remoteiew不支持spannablestring,至少不支持imagespan。这就很无解了。

三、解决思路:因为notification有很多限制,尝试了很多都不行,最后决定用remoteview 的addview方法。遇到文字添加textview,遇到表情文字添加imageview。

暂时想到这样,有更好的方法请评论。

四、示例代码:

添加文字:

RemoteViews  textRemoteViews = new RemoteViews(context.getPackageName(), R.layout.notification_content_text);
                textRemoteViews.setTextViewText(R.id.tv_str,value.toString().substring(0,start));
                remoteViews.addView(R.id.ll_content,textRemoteViews);

添加图片:

RemoteViews  imageRemoteViews = new RemoteViews(context.getPackageName(), R.layout.notification_content_image);
                imageRemoteViews.setImageViewBitmap(R.id.iv_emoji,drawableToBitmap(d));
                remoteViews.addView(R.id.ll_content,imageRemoteViews);

如果想要完整代码可私信我,不过可能收费的。关键是思路

相关文章

网友评论

      本文标题:Android开发自定义通知栏内容显示表情

      本文链接:https://www.haomeiwen.com/subject/oyzpjltx.html