I want to add a image in text. I used SpannableStringBuilder to achieve that. But I am not able to give padding to the image icon. Please help me to add padding to the image icon.
My code snippet:
String text = "Hello world! ";
SpannableStringBuilder ssb = new SpannableStringBuilder(text);
ssb.setSpan(new ImageSpan(this, R.drawable.tick), text.length() - 1, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
tvMainText.setText(ssb, TextView.BufferType.SPANNABLE);
Output:
Here I want to add right and left padding for the image. Please help me on this.

Instead of
String text = "Hello world! ";Define
text = "Hello world! *symbol* ";Int startIndex = text.indexOf("*symbol*");pass the indices of the first and second asterisk (*) as start and end params of setSpan respectively like this
ssb.setSpan(new ImageSpan(this, R.drawable.tick), startIndex, startIndex + 8, Spanned.SPAN_INCLUSIVE_INCLUSIVE);