Skip to content

Instantly share code, notes, and snippets.

@prashantvc
Created October 3, 2013 08:52
Show Gist options
  • Save prashantvc/6807148 to your computer and use it in GitHub Desktop.
Save prashantvc/6807148 to your computer and use it in GitHub Desktop.
using Android.App;
using Android.Content;
using Android.Widget;
using Android.OS;
using Android.Text;
using Android.Graphics.Drawables;
namespace TextviweWithImage
{
[Activity (Label = "TextviweWithImage", MainLauncher = true)]
public class MainActivity : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
TextView tv = (TextView)this.FindViewById (Resource.Id.text);
const string testContent = "<html><body><b>Test</b><i>Italic</i><br/>"
+ "<img src=\"Icon.png\"/>This is like testing if this thing works"
+ "<img src=\"Icon.png\"/>" + " in a more elaborate</body></html>";
tv.SetText (Html.FromHtml (testContent, new ImageGetter (this), null), null);
}
public class ImageGetter : Java.Lang.Object, Html.IImageGetter
{
readonly Context context;
public ImageGetter (Context context)
{
this.context = context;
}
public Drawable GetDrawable (string source)
{
var ld = new LevelListDrawable ();
//using static resources, load images based on the source
var drawable = context.Resources.GetDrawable (Resource.Drawable.Icon);
ld.AddLevel (0, 0, drawable);
ld.SetBounds (0, 0, drawable.IntrinsicWidth, drawable.IntrinsicHeight);
return ld;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment