开发者

ImageSpan in a widget?

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())) {
开发者_Go百科    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 your Uri. If that works, try putting them as drawable resources and using the resource IDs. Or, try the resource Uri syntax:

Uri.parse("android.resource://your.package.name.goes.here/" + R.raw.myvideo);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜