Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write % in strings.xml of android

Tags:

android

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> </string-array> 

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?

like image 944
mudit Avatar asked Oct 22 '12 12:10

mudit


People also ask

What is string in xml?

Note: A string is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). So, you can combine string resources with other simple resources in the one XML file, under one <resources> element. file location: res/values/filename.xml. The filename is arbitrary.

Why do we use string xml in Android?

xml , you can easily translate your whole app into other languages. This saves you a lot of work instead of doing this the hardcoded way: Android automatically selects the correct language based on user preferences, and you don't have to worry about selecting and displaying this language.

How do you write and in string?

In android studio, you can simply press Alt+Enter and it will convert for you.

How do I make a string bold in xml?

Just use getText(R. string.


2 Answers

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

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

with

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

like image 89
ban-geoengineering Avatar answered Oct 14 '22 02:10

ban-geoengineering


You can use its code. Try this: &#37;

Also check the similar question: Android XML Percent Symbol

like image 33
olshevski Avatar answered Oct 14 '22 03:10

olshevski