呼唤远方
这就是我使用的方法,不需要您对资源名称进行硬核化,并且会在没有找到任何内容的情况下先在您的应用程序资源中查找可绘制资源,然后在库存的android资源中查找可绘制资源-允许您使用默认图标等。private class ImageGetter implements Html.ImageGetter { public Drawable getDrawable(String source) { int id; id = getResources().getIdentifier(source, "drawable", getPackageName()); if (id == 0) { // the drawable resource wasn't found in our package, maybe it is a stock android drawable? id = getResources().getIdentifier(source, "drawable", "android"); } if (id == 0) { // prevent a crash if the resource still can't be found return null; } else { Drawable d = getResources().getDrawable(id); d.setBounds(0,0,d.getIntrinsicWidth(),d.getIntrinsicHeight()); return d; } } }可以这样使用(示例):String myHtml = "This will display an image to the right <img src='ic_menu_more' />";myTextview.setText(Html.fromHtml(myHtml, new ImageGetter(), null);