【发布时间】:2010-06-21 17:56:56
【问题描述】:
我正在尝试在主屏幕小部件上动态显示图像。由于 RemoveViews 提供了一组非常有限的与布局交互的方法,因此我尝试使用 HTML 来获得相同的效果。
常规 HTML 显示正常(<u>,<b> 等),但我无法显示图像。相反,我在 TextView 中出现了一个小空方块。
例如
s = "<b>Hello</b> <img src='world'/>";
ImageGetter imgGetter = new ImageGetter(context);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setTextViewText(R.id.textarea, Html.fromHtml(s, imgGetter, null));
图像获取器如下所示:
public class ImageGetter implements Html.ImageGetter
{
Context c;
public ImageGetter(Context c)
{
this.c = c;
}
public Drawable getDrawable(String source) {
Drawable d = null;
int resID = c.getResources().getIdentifier(source, "drawable", c.getPackageName());
d = c.getApplicationContext().getResources().getDrawable(resID);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
}
如果我使用常规 Activity,该代码可以正常工作。当与 AppWidgetProvider 一起使用时,我怀疑这是 android 的一个错误/未记录的功能。我只是想要一些确认。
【问题讨论】:
-
我可以确认。在 RemoteViews 中使用时不显示图像