繁体   English   中英

在android的strings.xml中写入%

[英]Write % in strings.xml of android

我想在我的strings.xml文件中创建以下字符串数组:

<string-array name="an_array_columns">
         <item>% Select percentage1</item>
         <item>% Select percentage2</item>
</string-array>

这里的字符串是“% select percentage”。 现在,当我在我的 strings.xml 中写这个时,我收到以下错误:

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

我知道我们可以将&更改为&amp; ' to \' ,但我该如何处理百分号?

%%似乎对我有用。 例如:

<string name="num_percent">%1$d %%</string>

String oneHundredPercentString = getString(R.string.num_percent, 100); // This gives "100 %"

您可以使用其代码。 试试这个: &#37;

还要检查类似的问题: Android XML百分比符号

如果我们想要字符串中的 % 符号,那么试试

<string name="_150_chance_for_a_beautiful_sky">150\% chance for a beautiful sky.</string>
binding.percentageCheck.setText(getResources().getString(R.string._150_chance_for_a_beautiful_sky));

如果我们想格式化数据,那么试试

    <string name="test_percent">First : %d, Second : %s, third :%f, Second : %c  </string>

    String multiPercent = getResources().getString(R.string.test_percent, 150 , "Test", 2f, 'c');
    binding.multiPercentageCheck.setText(multiPercent);

输出

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM