Andrid中的plurals
16lz
2021-01-26
在Android中的字符串资源中,今天留意到一个很特别的东西,叫plurals,其实际的意思就是因为英文中有单,复数之分,所以有的时候,当涉及到数量时,可以在字符串资源中
使用这个玩意来进行动态替换,比如:
使用的时候:
其中第2个参数是实际的个数,比如是通过程序计算出来的,第3个参数是对应使用哪一个复数形式,比如one car,two cars这样,还支持:
•zero
•one
•two
•few
•many
•other
但可惜大部分语言都不大支持这样单复数形式,所以只能英文中使用
使用这个玩意来进行动态替换,比如:
<xml version="1.0" encoding="utf-8"?> <resources> <plurals name="numberOfCars"> <item quantity="one">%d car</item> <item quantity="other">%d cars</item> </plurals> </resources>
使用的时候:
// Get the number of cars int count = getNumberOfCars(); Resources res = getResources(); String cars = res.getQuantityString(R.plurals.numberOfCars, count, count);
其中第2个参数是实际的个数,比如是通过程序计算出来的,第3个参数是对应使用哪一个复数形式,比如one car,two cars这样,还支持:
•zero
•one
•two
•few
•many
•other
但可惜大部分语言都不大支持这样单复数形式,所以只能英文中使用
更多相关文章
- http通信,Android(安卓)Gzip压缩解压
- InputFilter方法filter 解释
- ImageView 长按保存
- Android中正则表达式的常用判断
- Android实现计数器功能
- Android(安卓)中英文切换工具类
- instrumentation
- android text 中英文混排 换行的问题
- android driver开发常见的英文缩写