Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to show single textview in different color?

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 593
    Answer it

    Hello everyone,

    i have this 

    <string name="disclaim">DISCLAIMER:Next Vision Research Solutions Pvt. Ltd. holds the right of refusal/cancel/acceptance of the junk responses either intentionally or unintentionally submitted by anyone and Next Vision Research Solutions Pvt. Ltd. will not be held liable to pay for any such junk responses. Payment shall be made only after ensuring the quality /authenticity on certain parameters of the submitted responses. We are bound to ensure 100 % quality across India with zero tolerance on fudging.                                         "</string>

    and I want to show this in single textview but in different color like DISCLAIMER: is in red color and other remaining text in black color.

    is it possible without using more textview?

    plz if any possible solution is there tell me.

 1 Answer(s)

  • You can use the following code:-
    In your case startIndex is 0 and endIndex is 9
    TextView TV = (TextView)findViewById(R.id.mytextview01);
    
    Spannable wordtoSpan = new SpannableString("your string");        
    
    wordtoSpan.setSpan(new ForegroundColorSpan(Color.RED), startIndex, EndIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    
    TV.setText(wordtoSpan);
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: