TextView 显示 HTML 图片

在 TextView 中展示 HTML 图片


如果您需要在 Android 的 TextView 控件中嵌入 HTML 代码并显示其中的图片,您可以使用 SpannableStringBuilder。这个类允许您对文本进行格式化操作,包括添加链接、图像和格式化的文本等。以下是示例代码:

```java
String html = "<html><body></body></html>");
Spanned spannedHtml = Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
TextView textView = findViewById(R.id.textView1);
textView.setText(spannedHtml);
```
在上面的代码中,我们首先定义了一个包含 HTML 标签的字符串。然后,我们使用 `Html.fromHtml()` 方法将这个字符串转换为一个可编辑的 SpannedStringBuilder 对象。最后,我们将这个对象设置为 TextView 的内容。
folder
TextView加载Html图片 预估大小:870个文件
file
gradlew.bat 2KB
file
app-debug.apk 1.05MB
file
app-debug-unaligned.apk 1.05MB
file
MediaMetadataCompat.aidl 680B
file
ParcelableVolumeInfo.aidl 689B
file
PlaybackStateCompat.aidl 688B
file
MediaSessionCompat.aidl 787B
file
RatingCompat.aidl 673B
file
resources-debug.ap_ 380KB
file
resources-debug-androidTest.ap_ 763B
file
R$styleable.class 18KB
file
R$style.class 18KB
file
R$attr.class 9KB
file
R$styleable.class 18KB
file
R$style.class 18KB
file
fileSnapshots.bin 757KB
file
outputFileStates.bin 19KB
file
fileHashes.bin 88KB
file
taskArtifacts.bin 65KB
file
gradle_project_sync_data.bin 594B
rar 文件大小:5.87MB