Android XML百分比符号

本文翻译自:Android XML Percent Symbol

I have an array of strings in which the % symbol is used. 我有一个字符串数组,其中使用%符号。 Proper format for using the % is % 使用%正确格式是% . When I have a string in that array with multiple % 当我在该数组中有一个带有多个% it gives me this error. 它给了我这个错误。

 Multiple annotations found at this
 line:
 - error: Multiple substitutions specified in non-positional format;
   did you mean to add the formatted="false" attribute?
 - error: Found tag </item> where </string-array> is expected

#1楼

参考:https://stackoom.com/question/iwnP/Android-XML百分比符号


#2楼

试试这个(右):

<string name="content" formatted="false">Great application %s  ☞  %s  ☞  %s \\n\\nGo to download this application %s</string>

#3楼

In your strings.xml file you can use any Unicode sign you want. 在strings.xml文件中,您可以使用任何所需的Unicode符号。

For example, the Unicode number for percent sign is 0025: 例如,百分号的Unicode编号为0025:

<string name="percent_sign">&#x0025;</string>

You can see a comprehensive list of Unicode signs here 您可以在此处查看完整的Unicode标志列表


#4楼

This could be a case of the IDE becoming too strict. 这可能是IDE变得过于严格的情况。

The idea is sound, in general you should specify the order of substitution variables so that should you add resources for another language, your java code will not need to be changed. 这个想法很合理,一般来说你应该指定替换变量的顺序,这样如果你为另一种语言添加资源,你的java代码就不需要改变了。 However there are two issues with this: 但是这有两个问题:

Firstly, a string such as: 首先,字符串如:

You will need %.5G %s

to be used as You will need 2.1200 mg will have the order the same in any language as that amount of mass is always represented in that order scientifically. 使用, 你将需要2.1200毫克将使任何语言的顺序相同,因为质量总是科学地按顺序表示。

The second is that if you put the order of variables in what ever language your default resources are specified in (eg English) then you only need to specify the positions in the resource strings for languages the use a different order to your default language. 第二个是如果你把变量的顺序放在你的默认资源中指定的语言(例如英语),那么你只需要在语言的资源字符串中指定使用与默认语言不同的顺序的位置。

The good news is that this is simple to fix. 好消息是这很容易解决。 Even though there is no need to specify the positions, and the IDE is being overly strict, just specify them anyway. 尽管不需要指定位置,并且IDE过于严格,但无论如何都要指定它们。 For the example above use: 对于上面的例子,使用:

You will need %1$.5G %2$s 你将需要%1 $ .5G%2 $ s


#5楼

Use 使用

<string name="win_percentage">%d%% wins</string>

to get 要得到

80% wins as a formatted string. 80% wins作为格式化字符串80% wins

I'm using String.format() method to get the number inserted instead of %d . 我正在使用String.format()方法来插入数字而不是%d


#6楼

A tricky method: using small percent sign as below 一个棘手的方法:使用如下的小百分号

 <string name="zone_50">Fat Burning (50&#65130; to 60&#65130;)</string> 

Percent Sign on Wikipedia 维基百科上的百分号

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值