Android string Partial discoloration:

Source: Internet
Author: User

Arg0:<string name= "Red_number" > Quantity%1$s</string>
</pre><pre name= "code" class= "java" style= "Background-color:rgb (255, 255, 255); ">ARG1:" 123456 "
<span style= "Background-color:rgb (255, 255, 255); "> Show Effect: Quantity </span><span style=" Background-color:rgb (255, 102, 102); " >123456</span>

</pre><pre name= "code" class= "Java" >
/** *  * @param context * @param arg0 string    * @param arg1 number   * @return */public spannablestringbuilder setred (Con Text context, int arg0, string arg1) {string text = String.Format (Context.getresources (). getString (arg0), arg1); int index [] = new Int[1];index[0] = Text.indexof (arg1);//index[1] = Text.indexof ("+");//index[2] = Text.indexof ("Silver Chest"); Spannablestringbuilder style = new Spannablestringbuilder (text); Style.setspan (new Foregroundcolorspan (Color.RED), Index[0],index[0] + arg1.length (), spannable.span_exclusive_inclusive)//style.setspan (New ForegroundColorSpan ( color.red), index[1],//index[1] + 2, spannable.span_exclusive_inclusive);//style.setspan (New BackgroundColorSpan ( color.red), Index[2],//index[2] + 3, spannable.span_exclusive_inclusive); return style;}
That's it...

Android string Partial discoloration:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.