How to insert drawables in text

后端 未结 3 1364
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 11:02

I want to insert small pictures, like arrow icons for example, into certain positions of contents of a TextView.

The photo below depicts exactly what I

3条回答
  •  [愿得一人]
    2020-12-05 11:40

    You can create SpannableString and add any object to your string

    TextView textView = (TextView) findViewById(R.id.textView);
    
    ImageSpan imageSpan = new ImageSpan(this, R.drawable.ic_launcher);
    SpannableString spannableString = new SpannableString(textView.getText());
    
    int start = 3;
    int end = 4;
    int flag = 0;
    spannableString.setSpan(imageSpan, start, end, flag);
    
    textView.setText(spannableString);
    

提交回复
热议问题