700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > android 字符长度限制 中文2个字符 英文1个字符

android 字符长度限制 中文2个字符 英文1个字符

时间:2021-01-21 05:43:31

相关推荐

android 字符长度限制 中文2个字符  英文1个字符

比如最大10个字符,若超过10个,则显示9或者8个字符加省略号.

啊啊啊啊啊

哎哎哎啊...

哎哎哎啊a...

aaaaaaaa...

public class CalTextLength {

public static String handleText(String str, int maxLen) {if (TextUtils.isEmpty(str)) {return str; }int count = 0; int endIndex=0; for (int i = 0; i < str.length(); i++) {char item = str.charAt(i); if (item < 128) {count = count + 1; } else {count = count + 2; }if(maxLen==count || (item>=128 && maxLen+1==count)){endIndex=i; }}if (count <= maxLen) {return str; } else {return str.substring(0, endIndex) + "..."; }}

}

private static final intmaxLen=12; //名字最大字符数

tring name=CalTextLength.handleText(simpleContact.getName(),maxLen);holder.tv_name.setText(name);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。