Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9026603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:33:43+00:00 2026-06-16T06:33:43+00:00

I want to bold multiple words from textview’s text. I am having words in

  • 0

I want to bold multiple words from textview’s text.
I am having words in array that i want to bold in textview’s text.
how to do it by SpannableStringBuilder??

My array:

string[] array =
{“Life”,”happiness”,”sadness”,”tears”,”smiles”,”laughter”,”emotions”};

My Textview text:

Life is filled with happiness, sadness, tears, smiles, laughter and
other emotions but when life gets you down, just be strong about it
and keep your head up high and have faith in all things in life.

I go through link and other but not found any solution which i want.

    TextView text = (TextView) findViewById(R.id.textView1);
    String[] list = new String[] { "Life","happiness","sadness","tears","smiles","laughter","emotions"};    

    String textData ="Life is filled with happiness, sadness, tears, smiles, laughter and other emotions but when life gets you down, just be strong about it and keep your head up high and have faith in all things in life";
    CharSequence cseq = "";
    for(int i = 0 ; i < list.length ; i++)
    {
          cseq = setSpanBetweenTokens(textData, list[i] , new StyleSpan(Typeface.BOLD_ITALIC));
    }
    text.setText(cseq.toString()); 


public static CharSequence setSpanBetweenTokens(CharSequence text,
            String token, CharacterStyle... cs)
        {
            // Start and end refer to the points where the span will apply
            int tokenLen = token.length();
            int start = text.toString().indexOf(token) + tokenLen;
            int end = text.toString().indexOf(token, start);

            if (start > -1 && end > -1)
            {
                // Copy the spannable string to a mutable spannable string
                SpannableStringBuilder ssb = new SpannableStringBuilder(text);
                for (CharacterStyle c : cs)
                    ssb.setSpan(c, start, end, 0);

                // Delete the tokens before and after the span
                ssb.delete(end, end + tokenLen);
                ssb.delete(start - tokenLen, start);

                text = ssb;
            }

            return text;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:33:45+00:00Added an answer on June 16, 2026 at 6:33 am

    try as using Html.fromHtml:

    string[] array = {"Life","happiness","sadness",
    "tears","smiles","laughter","emotions"};
    
    String strtemp="";
        for(int i=0;i<array.length-2;i++){
         if(i<array.length-3)
           strtemp+="<b>"+array[i]+",<b/>";
          else{
           strtemp+="<b>"+array[i]+"<b/>";
         }
        }
        txtview=(TextView)findViewById(R.id.selection);
        txtview.setText(Html.fromHtml("YOUR_TEXT HERE"+strtemp+
                 "YOUR_TEXT HERE <b>"+array[array.length-1]
                         +"</b> YOUR_TEXT HERE"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create labels in MFC (Static text) that have both bold and
I want to style my content with some bold text and even linked text.
I want to have a left justified label with some bold text in it,
I my application i want to make the text seleected selected using mouse bold..How
i want the following functionality. input : this is test <b> bold text </b>
I want to bold and color of single textview item.ex- 23870.This is a value
I have the following string: This *is* a *test*! I want to bold the
I want to apply style(blue font) for the matching words in a particular string
Hi I have created an app that i want to run across multiple screens
Basically I just want bold, italic, underline. Nothing complicated. I've read from other questions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.