Android getText(int resId) 与 getString(int resId)的区别

Android提供两个获取strings.xml文件的方法:

CharSequence getText(int resId):返回本地、样式化的字符。
String getString(int resId) :单纯返回字符串

如:

  strings.xml中定义资源文件:

  <string name="sample_text">Plain, <b>bold</b>, <i>italic</i>, <b><u>bold-underline</u></b></string>

  getText(R.string.sample_text);
  getResource().getText(R.string.sample_text);

  getString(R.string.sample_text);

效果图

样式化的定义:

<b></b>加粗字体

<i></i> 斜体字体

<u></u> 给字体加下划线

参考:http://blog.sina.com.cn/s/blog_5da93c8f01012zhb.html

原文地址:https://www.cnblogs.com/zhangyulogin/p/4250550.html