Created
August 14, 2020 23:44
-
-
Save shuanghua/ee70efc93d93470bf48cb82ecec1a034 to your computer and use it in GitHub Desktop.
android 设置指定字符样式
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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