Display HTML String with multi images on TextView, with Html.ImageGetter
Previous example load single image in HTML String with Html.ImageGetter. This example load two different images in HTML String. Because both images in drawable, so we can use a common Html.ImageGetter.Display HTML String with multi images on TextView, with Html.ImageGetter |
package com.example.androidhtmltextview;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
String htmlString = "<img src='ic_launcher'><i>Welcome to<i> <b><a href='http://android-coding.blogspot.com'>Android Coding</a></b>" +
"<br/>" +
"<img src='page'><b><a href='https://plus.google.com/b/113141750089533146251/'>My G+ Page</a></b><br/>";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView htmlTextView = new TextView(this);
setContentView(htmlTextView);
htmlTextView.setText(Html.fromHtml(htmlString, new Html.ImageGetter(){
@Override
public Drawable getDrawable(String source) {
Toast.makeText(getApplicationContext(),
source,
Toast.LENGTH_LONG).show();
Drawable drawable;
int dourceId =
getApplicationContext()
.getResources()
.getIdentifier(source, "drawable", getPackageName());
drawable =
getApplicationContext()
.getResources()
.getDrawable(dourceId);
drawable.setBounds(
0,
0,
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());
return drawable;
}
}, null));
htmlTextView.setMovementMethod(LinkMovementMethod.getInstance());
}
}
Next: Html.ImageGetter load image from internet
0 komentar:
Posting Komentar