用Spannable字符串实现:
String s= "Hello Everyone"; SpannableString ss1= new SpannableString(s); ss1.setSpan(new RelativeSizeSpan(2f), 0,5, 0); // set size ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, 5, 0);// set color TextView tv= (TextView) findViewById(R.id.textview); tv.setText(ss1);
效果如下:
Hello Everyone
也可以通过截取字符串里面的空格来展示不同文字的大小,截取如下:
String[] each; String s= "Hello Everyone"; for(int i=0;i<s.length();i++) { each = s.split("\s"); }