How to replace String with an image inside an EditText?

前端 未结 2 1003
生来不讨喜
生来不讨喜 2021-01-24 12:13

I am currently working on a simple chat application. I want to add emoticons features in this app. I already have a function to receive string from other users. What I want is-

2条回答
  •  梦谈多话
    2021-01-24 12:49

    You can try like this

     if (rosan.contains(":p")){
                int span = abc.indexOf(":p");
                res = getResources().getDrawable(R.drawable.myImage); 
                res.setBounds(0, 0, res.getIntrinsicWidth(), res.getIntrinsicHeight());
                span = new ImageSpan(res, ImageSpan.ALIGN_BASELINE);
                ss.setSpan(span, startSpan, startSpan+2, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                rosan = rosan.replaceFirst(":D","  "); //replace with two blank spaces.
            }
    

提交回复
热议问题