不同的语言对数量的定义有不同的语法规则。例如,在英语中,1个指的是一种特殊情况。其他时候我们说n个。这种单数和复数的情况非常的普通。但其他语言却有明显的区别。Android中设置了0,1,2,"很少",“许多”和“其他”做为数量表述。

对于给定的语言和数量,决定使用那种情况是非常的困难和复杂的。Android提供了getQuantityString()来帮助我们决定选择适当的资源。

语法:

<?xml version="1.0" encoding="utf-8"?><resources>
    <plurals
        name="plural_name">
        <item
            quantity=["zero" | "one" | "two" | "few" | "many" | "other"]
            >text_string</item>
    </plurals></resources>

 

文件位置:res/values/filename.xml
如何引用:R.plurals.plural_name

例子:

<?xml version="1.0" encoding="utf-8"?>
<resources>
   
<pluralsname="numberOfSongsAvailable">
       
<itemquantity="one">One song found.</item>
       
<itemquantity="other">%d songs found.</item>
   
</plurals>
</resources>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-12
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2021-09-28
猜你喜欢
  • 2022-01-18
  • 2021-10-01
  • 2021-06-17
  • 2021-10-11
  • 2021-09-19
  • 2021-06-15
  • 2021-04-25
相关资源
相似解决方案