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?
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.
Escapes or unescapes an XML file removing traces of offending characters that could be wrongfully interpreted as markup.
Use & in place of & .
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.
use this way ..............
<string name="at">\@</string>
android:text="\@"
^
instead of
android:text="@"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With