-1

I need text with icon in the middle of the text for two locale like image below for example.enter image description here

TikTak
  • 713
  • 1
  • 11
  • 23
  • What is the format of your string. is icon came with string format? plase share more details. – InsaneCat Feb 29 '20 at 08:28
  • You should look into Spannables https://medium.com/androiddevelopers/spantastic-text-styling-with-spans-17b0c16b4568 – Blundell Feb 29 '20 at 08:31
  • Please take a look on this answer https://stackoverflow.com/questions/15352496/how-to-add-image-in-a-textview-text/38977396 – Roman Feb 29 '20 at 08:34
  • @InsaneCat I have plain text and vector icon or png icon and I need to do like image above. – TikTak Feb 29 '20 at 08:35

1 Answers1

2

Spannables can be customised to use images, aka ImageSpan

https://medium.com/androiddevelopers/spantastic-text-styling-with-spans-17b0c16b4568

https://developer.android.com/reference/android/text/style/ImageSpan

 SpannableString string = new SpannableString("Bottom: span.\nBaseline: span.");
 string.setSpan(new ImageSpan(this, R.mipmap.ic_launcher), 7, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 string.setSpan(new ImageSpan(this, R.mipmap.ic_launcher, DynamicDrawableSpan.ALIGN_BASELINE), 22, 23, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

Blundell
  • 75,855
  • 30
  • 208
  • 233