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; 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>"; @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) { 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()); } }
Display HTML String with img on TextView |
Next: Display HTML String with multi images on TextView, with Html.ImageGetter
Thank you very much! It helps!
ReplyDeleteI need help from sir before that thank you very much for sharing your code with us.
ReplyDeleteHow to show multiple images in text view.
These would help me much
Thank you
hello viveknandhan reddy,
ReplyDeleteplease read: Display HTML String with multi images on TextView, with Html.ImageGetter.
Hi, by this method can I show local assets folder image...?
ReplyDelete