How to write `@` symbol in android TextView at starting

Viewed 1534

I want to write text starting with @ symbol in TextView. But, when I write it in both places as a hardcoded and using string resource, the error says missing /. When I type some characters before @, it works fine. But, I want to write it at the beginning. How to achieve this?

3 Answers

Use it like this \@

<string name="character">\@ character</string>

Or you can use the Unicode character \0040

Add Unicode character in String.xml like

<string name="character">\u0040 character</string>

add this in your textview like :

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/character"/>

Here \u0040 indicates ' @ ' sign.

Simply write "\@" as the error says ;) (it's a special character that need to be escaped with a "\")

Related