Text Box Tool class--textviewutil

Source: Internet
Author: User

this tool class features:

Set part size to TextView
Set some colors for TextView
Set the underline for TextView
Half-width conversion to full-width
Remove special characters or replace all Chinese labels with English labels

/** * Created by Peng on 2015/06/16. * Text Box tool class */ Public  class textviewutil {    //Set part size to TextView     Public Static void setpartialsize(TextView TV,intStartintEndintTextSize) {String s = Tv.gettext (). toString (); Spannable spannable =NewSpannablestring (s); Spannable.setspan (NewAbsolutesizespan (TextSize), start, end, spannable.span_exclusive_exclusive);    Tv.settext (spannable); }//Set some color for TextView     Public Static void Setpartialcolor(TextView TV,intStartintEndintTextColor) {String s = Tv.gettext (). toString (); Spannable spannable =NewSpannablestring (s); Spannable.setspan (NewForegroundcolorspan (TextColor), start, end, spannable.span_exclusive_exclusive);    Tv.settext (spannable); }//Set the underline for TextView     Public Static void Setunderline(TextView TV) {if(Tv.gettext ()! =NULL) {String udata = Tv.gettext (). toString (); spannablestring content =NewSpannablestring (Udata); Content.setspan (NewUnderlinespan (),0, Udata.length (),0);            Tv.settext (content); Content.setspan (NewUnderlinespan (),0, Udata.length (),0); }Else{Tv.getpaint (). SetFlags (Paint.underline_text_flag); }    }//Cancel the TextView underline     Public Static void Clearunderline(TextView TV) {Tv.getpaint (). SetFlags (0); }//half angle converted to full angle     Public StaticStringTodbc(String input) {Char[] C = Input.tochararray (); for(inti =0; i < c.length; i++) {if(C[i] = =12288) {C[i] = (Char) +;Continue; }if(C[i] >65280&& C[i] <65375) C[i] = (Char) (C[i]-65248); }return NewString (c); }//Remove special characters or replace all Chinese labels with English numerals     Public StaticStringReplacecharacter(String str) {str = Str.replaceall ( "" ","["). ReplaceAll ( "" ","]"). ReplaceAll ("! ","!"). ReplaceAll (":",":"). ReplaceAll ("(","("). ReplaceAll ("(",")");//Replace Chinese markingString regEx ="[" "]";//Clear out special charactersPattern p = pattern.compile (regEx); Matcher m = p.matcher (str);returnM.replaceall (""). Trim (); }}

Text Box Tool class--textviewutil

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.