Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Android.App;
- using Android.Text;
- using Android.Text.Style;
- using Android.Widget;
- using Android.OS;
- namespace MonoDroid.TextViewWithImages
- {
- [Activity(Label = "Text with Images", MainLauncher = true, Icon = "@drawable/icon")]
- public class Activity1 : Activity
- {
- private EditText _editText;
- protected override void OnCreate(Bundle bundle)
- {
- base.OnCreate(bundle);
- // Set our view from the "main" layout resource
- SetContentView(Resource.Layout.Main);
- var textView = FindViewById<TextView>(Resource.Id.textView1);
- var imageSpan = new ImageSpan(this, Resource.Drawable.Icon); //Find your drawable.
- var spannableString = new SpannableString(textView.Text); //Set text of SpannableString from TextView
- spannableString.SetSpan(imageSpan, textView.Text.Length -1, textView.Text.Length, 0); //Add image at end of string
- textView.TextFormatted = spannableString; //Assign string to TextView (Use TextFormatted for Spannables)
- _editText = FindViewById<EditText>(Resource.Id.editText1);
- _editText.AfterTextChanged += (sender, args) => SpannableTools.AddSmiles(this, args.Editable);
- }
- }
- }
Add Comment
Please, Sign In to add comment