How to highlight the filtered text while using SearchView widget in android?

February 01, 2018 , 0 Comments

Example How it Works:

FullText : What is your Favorite Songs?
searchText : What Song

Result :  What is your Favorite Songs?

Use this Methods :
public static Spanned setTitlebols(String fullText, String searchText) {

Spanned span;
searchText = searchText.replace("'", "");
searchText = searchText.replace("?", "");

String[] words = searchText.split(" ");

// highlight search text
if (null != searchText && searchText.length() != 0) {

try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
for (String wr : words) {
fullText = fullText.replaceAll("(?i)(" + wr + ")", "<span><b><strong><font>$1</font></strong></b></span>");
}
span = Html.fromHtml(fullText, Html.FROM_HTML_MODE_LEGACY);
// , TextView.BufferType.SPANNABLE
} else {
for (String wr : words) {
fullText = fullText.replaceAll("(?i)(" + wr + ")", "<b><big>$1</font></big></b>");
}
span = Html.fromHtml(fullText);
}
} catch (Exception e) {
span = Html.fromHtml(fullText);
}

} else {
span = Html.fromHtml(fullText);
}

return span;
}

 

 

 

Contributer

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google

0 comments:

Hot-product

Best Watch Store

Popular Posts

Contact Form

Name

Email *

Message *