Home » Android » Write % in strings.xml of android

Write % in strings.xml of android

Posted by: admin April 23, 2020 Leave a comment


I want to create the following string array in my strings.xml file:

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

here the string is “% select percentage”. Now, when I am writing this in my strings.xml, I am getting the following 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

I know we can change & to &amp; or ' to \', but what do I do for percentage sign?

How to&Answers:

You can use its code. Try this: %

Also check the similar question: Android XML Percent Symbol


%% seems to be all that works for me. For example:

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


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