0

I am using <string-array> in my string.xml file. Inside this, I have multiple tags. Also, I am showing this text in TextView on a Fragment.

Now, in some of these item tags I want to embed images. The issue is, I want to add these images in between the text inside <item> tag.

I am successfully able to add image at top, bottom or left of the TextView but not able to embed that in between the text.

Can anyone please let me know how to achieve this ?

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
Sushant Sharma
  • 103
  • 1
  • 8

1 Answers1

0

1/ no you can't add a reference in string.xml. 2/ you can do it by java using ImageSpan and SpannableString this way:

ImageSpan is = new ImageSpan(context, resId);
text.setSpan(is, index, index + strLength, 0);

exemple :

ImageSpan is = new ImageSpan(context, R.drawable.arrow);
SpannableString text = new SpannableString("Lorem ipsum dolor sit amet");
text.setSpan(is, 5, 5 + 10, 0);
Community
  • 1
  • 1
ahmed_khan_89
  • 2,755
  • 26
  • 49