private String fomatPhone(String phone){
String no="";
if(!TextUtils.isEmpty(phone)){
for(int i=0;i<phone.length();i++){
char c=mUserInfo.phone.charAt(i);
if(i>2 && i<phone.length()-4){
no+="*";
}else{
no+=c;
}
}
}
return no;
}
不过我之前还想到一种,就是用分割:
private String phone="13816175809";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String str1=phone.substring(0, 2);
String str2=phone.substring(phone.length()-4,phone.length());
((Button)findViewById(R.id.btn)).setText(str1+"****"+str2);
手机中间四位为***** 138*****580
最新推荐文章于 2022-01-13 15:27:33 发布