Insert a ImageSpan into SpannableString .
ImageSpan is built with the drawable to insert and the SpannableString with the text where it will be inserted.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
TextView textView = findViewById(R.id.textView);
String text = "texto ? texto";
//Posição onde colocar a imegem(posição da marca)
int imagePos = text.indexOf("?");
//Criar um SpannableString do texto
SpannableString spannableString = new SpannableString(text);
//Obter o drawable a inserir
Drawable drawable = getResources().getDrawable(R.mipmap.ic_launcher);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
//Criar um ImageSpan do drawable
ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
//Inserir a imagem(ImageSpan) no texto(SpannableString)
spannableString.setSpan(imageSpan,imagePos,imagePos+1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
//Atribuir o texto com a imagem ao TextView
textView.setText(spannableString);
}
The principle is this. Adjust to your needs.