在小部件ImageSpan? [英] ImageSpan in a widget?
问题描述
在那里加入ImageSpan到窗口小部件是否有限制?
此相同的code在一个标准的TextView的正常工作。
SpannableStringBuilder BUF =新SpannableStringBuilder();
如果(!TextUtils.isEmpty(message.getMessageBody())){
SmileyParser解析器= SmileyParser.getInstance();
buf.append(parser.addSmileySpans(组message.getMessageBodyWithoutName():message.getMessageBody()));
}
view.setTextViewText(R.id.message_body,BUF);
感谢。
编辑1:
公开的CharSequence addSmileySpans(CharSequence的文字){
SpannableStringBuilder建设者=新SpannableStringBuilder(文本);匹配匹配= mPattern.matcher(文本);
而(matcher.find()){
INT渣油= mSmileyToRes.get(matcher.group());
builder.setSpan(新ImageSpan(mContext,渣油)
matcher.start(),matcher.end(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
返回建设者;
}
的笑脸的是当地的资产。
块引用>我要跨preT这从字面上看,你的意思是你的图像在
资产/
。我的猜测是,在主屏幕上有困难解决您的资产参考。作为测试,尝试把外部存储的图像,并使用
Uri.fromFile()
以创建你的乌里
。如果这样的作品,尝试把它们作为绘图资源和使用资源的ID。或者,尝试资源乌里
语法:Uri.parse(android.resource://your.package.name.goes.here/+ R.raw.myvideo);
Are there any limitations to adding an ImageSpan to a widget? This identical code works fine in a standard TextView.
SpannableStringBuilder buf = new SpannableStringBuilder(""); if(!TextUtils.isEmpty(message.getMessageBody())) { SmileyParser parser = SmileyParser.getInstance(); buf.append(parser.addSmileySpans(group ? message.getMessageBodyWithoutName() : message.getMessageBody())); } view.setTextViewText(R.id.message_body, buf);
Thanks.
Edit 1:
public CharSequence addSmileySpans(CharSequence text) { SpannableStringBuilder builder = new SpannableStringBuilder(text); Matcher matcher = mPattern.matcher(text); while (matcher.find()) { int resId = mSmileyToRes.get(matcher.group()); builder.setSpan(new ImageSpan(mContext, resId), matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } return builder;
}
解决方案The smiley's are local assets.
I am going to interpret this literally, that you mean your images are in
assets/
.My guess is that the home screen is having difficulty resolving your asset reference. As a test, try putting the images on external storage and using
Uri.fromFile()
to create yourUri
. If that works, try putting them as drawable resources and using the resource IDs. Or, try the resourceUri
syntax:Uri.parse("android.resource://your.package.name.goes.here/" + R.raw.myvideo);
这篇关于在小部件ImageSpan?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!