I have a textview which holds an image and some text.
programmatically i have added the drawable image to the left side of text view
txtIDFav.setCompound
Try this, it should work:
Spannable span = new SpannableString(" " + txtIDFav.getText()); // or set your text manually
Drawable drawable;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
drawable = getResources().getDrawable(R.drawable.fav_enabled, getContext().getTheme());
}
else
{
drawable = getResources().getDrawable(R.drawable.fav_enabled);
}
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
ImageSpan imageSpan = new ImageSpan(drawable);
span.setSpan(imageSpan, 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
txtIDFav.setText(span);