Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android XML escape "@" Symbol

How do you use the @ as text in an Android XML file, as it has special meaning? I have a TextView which will simply hold the text @

I tried:

<TextView
    android:id="@+id/at_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/account_name"
    android:gravity="center_horizontal"
    android:padding="3dip"
    android:text="@" />

That of course did not work with the error

error: Error: No resource type specified (at 'text' with value '@').

So I tried pointing it to an entry in strings.xml like this: <string name="at">@</string> and that shows the error:

error: Error: No resource type specified (at 'at' with value '@').

So how do I escape @ as the text for a TextView?

like image 646
Jeshurun Avatar asked Jun 23 '12 11:06

Jeshurun


People also ask

How do you escape Android?

If you need to escape a character that has special meaning in Android you should use a preceding backslash. By default Android will collapse sequences of whitespace characters into a single space. You can avoid this by enclosing the relevant part of your string in double quotes.

What is escaping XML?

Escapes or unescapes an XML file removing traces of offending characters that could be wrongfully interpreted as markup.

How do you pass ampersand in XML string?

Use &amp; in place of & .

How do you type escape characters?

Character combinations consisting of a backslash (\) followed by a letter or by a combination of digits are called "escape sequences." To represent a newline character, single quotation mark, or certain other characters in a character constant, you must use escape sequences.


2 Answers

use this way ..............

 <string name="at">\@</string>
like image 122
Dheeresh Singh Avatar answered Oct 18 '22 01:10

Dheeresh Singh


android:text="\@"
              ^

instead of

android:text="@"
like image 22
Samir Mangroliya Avatar answered Oct 18 '22 03:10

Samir Mangroliya