【问题标题】:Displaying images on android widgets using html & TextView使用 html 和 TextView 在 android 小部件上显示图像
【发布时间】: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 中使用时不显示图像

标签: android android-widget


【解决方案1】:

我正在尝试显示图像 在主屏幕小部件上动态显示。

使用ImageView。当您希望更改图像时更新应用小部件。

【讨论】:

    猜你喜欢
    • 2013-04-16
    • 2011-04-15
    • 2014-11-25
    • 1970-01-01
    • 2020-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多