Android string.xml
为我们的应用程序提供可选样式和格式的文本数据。可以有三种类型的字符串资源:字符串,字符串数组,复数。下面是Android string.xml
示例:
//普通字符串
<string name="string">Hello world!</string>
//单个string占位符
<string name="hello_str">Hello %s!</string>
//多个string占位符
<string name="string_w" formatted="false">%s 上了 %s 天班</string>
//加粗world
<string name="html_str"><![CDATA[Hello <b>world</b>!]]></string>
//hello world添加字体大小,行高,颜色以及换行
<string name="other_html_str"><![CDATA[<font style=\"font-size:12px;line-height:16px\" color=\"red\">Hello world!</font><br/><br/>换行了哦]]></string>
//复数
<plurals name="plural_string">
<item quantity="one">%s apple</item>
<item quantity="other">%s apples</item>
</plurals>
//字符串数组
<string-array name="array_of_strings">
<item>苹果</item>
<item>香蕉</item>
<item>橘子</item>
</string-array>
具体用法
LogUtil.debug(String.format(getResources().getString(R.string.hello_str),"我的"));
LogUtil.debug(String.format(getResources().getString(R.string.string_w),"我","3"));
tv1.setText(Html.fromHtml(String.format(getResources().getString(R.string.html_str))));
tv2.setText(Html.fromHtml(String.format(getResources().getString(R.string.other_html_str))));
String[] array = getResources().getStringArray(R.array.array_of_strings);
LogUtil.debug("array---->"+array[0]+" "+array[1]+" "+array[2]);
更多内容,请点击这里