前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android 资源文件

Android 资源文件

作者头像
code_horse
发布2018-07-02 14:25:52
8820
发布2018-07-02 14:25:52
举报
文章被收录于专栏:Android NoteAndroid Note

Android string.xml为我们的应用程序提供可选样式和格式的文本数据。可以有三种类型的字符串资源:字符串,字符串数组,复数。下面是Android string.xml示例:

代码语言:javascript
复制
    //普通字符串
    <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>

具体用法

代码语言:javascript
复制
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]);

更多内容,请点击这里

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018.01.22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档