Guest User

Untitled

a guest
Jul 29th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. using Android.App;
  2. using Android.Text;
  3. using Android.Text.Style;
  4. using Android.Widget;
  5. using Android.OS;
  6.  
  7. namespace MonoDroid.TextViewWithImages
  8. {
  9. [Activity(Label = "Text with Images", MainLauncher = true, Icon = "@drawable/icon")]
  10. public class Activity1 : Activity
  11. {
  12. private EditText _editText;
  13.  
  14. protected override void OnCreate(Bundle bundle)
  15. {
  16. base.OnCreate(bundle);
  17.  
  18. // Set our view from the "main" layout resource
  19. SetContentView(Resource.Layout.Main);
  20.  
  21. var textView = FindViewById<TextView>(Resource.Id.textView1);
  22.  
  23. var imageSpan = new ImageSpan(this, Resource.Drawable.Icon); //Find your drawable.
  24. var spannableString = new SpannableString(textView.Text); //Set text of SpannableString from TextView
  25. spannableString.SetSpan(imageSpan, textView.Text.Length -1, textView.Text.Length, 0); //Add image at end of string
  26.  
  27. textView.TextFormatted = spannableString; //Assign string to TextView (Use TextFormatted for Spannables)
  28.  
  29. _editText = FindViewById<EditText>(Resource.Id.editText1);
  30. _editText.AfterTextChanged += (sender, args) => SpannableTools.AddSmiles(this, args.Editable);
  31. }
  32. }
  33. }
Add Comment
Please, Sign In to add comment