Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Make String with different colors in Android

    • 0
    • 5
    • 0
    • 2
    • 0
    • 0
    • 0
    • 0
    • 553
    Comment on it

    We will use SpannableString to add different colors to a string and will use the setSpan(Object what, int start, int end, int flags) method of SpannableString to change the color for defined range of characters in that string.

    Here is the code:

    // this is the text we'll be operating on  
    TextView textView = new TextView(this);
    SpannableString text = new SpannableString("String in Android");  
    
    // make String blue  
    text.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.blue_color)), 0, 5, 0);  
    textView.setText(text, BufferType.SPANNABLE);  

    TextView will display the text "String in Android" where "String" will be in blue color.

    Hope this will help you :)

 0 Comment(s)

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: