user45678 user45678 - 4 months ago 30
Android Question

How to identify #hashtag and "http://" link from a string in android

is it possible to find a #hashtag and an "http://" link from a string and color it ? I am using this in Android.

public void setTitle(String title) {
this.title = title;

Thanks in Advance


I have found an answer and here is the way to do it :

        SpannableString hashtagintitle = new SpannableString(imageAndTexts1.get(position).getTitle());
        Matcher matcher = Pattern.compile("#([A-Za-z0-9_-]+)").matcher(hashtagintitle);
        while (matcher.find())
            hashtagintitle.setSpan(new ForegroundColorSpan(Color.BLUE), matcher.start(), matcher.end(), 0);