1。根据文件名获取id
public int getResourceid(String name){ try { String []s=name.split("\\."); Field field=R.drawable.class.getField(s[0]); return Integer.parseInt(field.get(null).toString()); } catch (Exception e) { Log.e("获取图片id", "失败"); e.printStackTrace(); } return 0; }2.根据图片的名字插入图片
CharSequence ch= Html.fromHtml(html, new Html.ImageGetter() { @Override public Drawable getDrawable(String source) { Drawable drawable = getResources().getDrawable(getResourceid(source)); drawable.setBounds(0,0,drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight()); return drawable; } }, null); tvTest2.setText(ch);