简体   繁体   中英

Android Replace all Occurrences of a text with a Html.fromHtml span

I need to display GIF emoticons within my textviews therefore I decided to replace all the occurrences of emoticons with their respective gif image using Html span. However I need a helping hand with replacing all occurrences of the emoji characters.

For example:

I had a good day (smile)

should be replaced by

I had a good day <img src: "path" />

What I was able to code so far:

string regex = " "; //this is where I need help with the regex
String output = comment.getComment().replaceAll(regex, "<img src='PATH' ");
commenttext.setText(Html.fromHtml(output));

If you simply do this String regex = "(\\(smile\\))"; This would replace all the (smile) occurrences. This is quite easy to do. Is this what you are looking for?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM