4

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?

Strooks
  • 183
  • 1
  • 10
  • Possible duplicates https://stackoverflow.com/questions/23608471/special-characters-android-textview – Deepak Kumar Aug 30 '18 at 12:31
  • @deepakkumar The question you linked is about different character, but I want to write `@` symbol, for which, the IDE is treating as a resource telling character. I want it as a hard coded string. – Strooks Aug 30 '18 at 12:37
  • The unicode for @ is \u0040 so all you have to do is mention it in your string tag like \u0040Deepak Kumar – Deepak Kumar Aug 30 '18 at 12:45

3 Answers3

7

Use it like this \@

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

Or you can use the Unicode character \0040

Prithvi Bhola
  • 3,041
  • 1
  • 16
  • 32
3

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.

Dhara Jani
  • 461
  • 3
  • 10
1

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

Bubu
  • 1,533
  • 14
  • 14