我一直在尝试将drawable
文件夹中的图片添加到通知行中。但图片未显示,而是显示[OBJ]
。
我可以在通知的任何其他地方添加图片。另外,我可以将emoji
添加到通知行中,例如此问题Android notification - custom inboxstyle (add line )。
但我无法添加图片。
有没有机会克服这个问题?
public void someMethod() {
...
mInboxStyle.addLine(imageSpanned());
...
}
private Spanned imageSpanned () {
String imgString = "Something <img src=\"ic_arrow_forward_black_24dp\">";
return Html.fromHtml(imgString, mImageGetter, null);
}
Html.ImageGetter mImageGetter = new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
Drawable drawable;
Resources res = mContext.getResources();
int drawableId = res.getIdentifier(source, "drawable", mContext.getPackageName());
drawable = res.getDrawable(drawableId);
int width = drawable.getIntrinsicWidth();
int height = drawable.getIntrinsicHeight();
drawable.setBounds(0, 0, width, height);
return drawable;
}
};
答案 0 :(得分:0)
您需要在ic_arrow_forward_black_24dp
或drawables
中提供mipmap
图标资源。
SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append("Something").append(" ");
builder.setSpan(
new ImageSpan(
getActivity(),
R.drawable.ic_arrow_forward_black_24dp),
builder.length() - 1,
builder.length(),
0
));
textView.setText(builder);