Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add < and > in android strings.xml

Tags:

android

I need to add <string name="name_hint"><Given Name></string> in strings.xml. What is the escape sequence in order to do that? The string to be added is <Given Name>

like image 395
user264953 Avatar asked Dec 13 '13 09:12

user264953


People also ask

How do you add and in a string?

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

What is the need of string xml in Android?

A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string.

What is the advantage of making strings in strings xml file?

One of the main benefits is for localization: you keep your code language-independent and just need to provide a different XML file for each language you want to support.

How do you do plurals in Android?

Multiple quantities in one string If your display text has multiple quantities, e. g. %d match(es) found in %d file(s). , split it into three separate resources: %d match(es) ( plurals item) %d file(s) ( plurals item)


2 Answers

The Android string.xml file is just a regular XML file, so you can use the XML escape characters:

"   &quot;
'   &apos;
<   &lt;
>   &gt;
&   &amp;

Your example would become <string name="name_hint">&lt;Given Name&gt;</string>

UPDATE: Furthermore you can use the HTML entities of each character, a blank space is for example &#032;, and a non-breaking space is &#160;.

Note that I am not entirely sure whether this is officially supported by the XML standards, or that it 'just works'...

like image 166
Veger Avatar answered Oct 17 '22 03:10

Veger


Use &lt; for less than symbol and &gt; for greater than symbol. so here you need to replace like:

<string name="name_hint">&lt;Given Name&gt;</string>
like image 30
Shailendra Madda Avatar answered Oct 17 '22 03:10

Shailendra Madda