Skip to content

Instantly share code, notes, and snippets.

@shuanghua
Created August 14, 2020 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuanghua/ee70efc93d93470bf48cb82ecec1a034 to your computer and use it in GitHub Desktop.
Save shuanghua/ee70efc93d93470bf48cb82ecec1a034 to your computer and use it in GitHub Desktop.
android 设置指定字符样式
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String str1 = "你有${ccccc}财产需要领";
//String str1 = "${ccccc}你有财产需要领$";
//String str1 = "你有财产需要领${ccccc}";
String str2 = "¥100";
String str3 = str2 + "&";
String str4 = str1.replace("${ccccc}", str3);
int index1 = str4.indexOf("¥");
int index2 = str4.indexOf("&");
String str5 = str4.replace("&", "");
System.out.println(str5);
System.out.println(index1);
System.out.println(index2);
SpannableString spanString = new SpannableString(str5);
spanString.setSpan(new AbsoluteSizeSpan(480),
index1 + 1,
index2,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
); //设置指定位置范围的字符大小
TextView textView = findViewById(R.id.text1);
textView.setText(spanString);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment