Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

special chars (@, ?) as xml-string in android app

Tags:

android

If i try to do things like this, it doesn't work... (empty string or no resource type error)

<string name="random">?</string>
<string name="random">@</string>

i also tried the html entity variant

<string name="random">&#63;</string>

any ideas how to use the "?" and "@" as string resource in android?

like image 310
Lord Midi Avatar asked May 13 '12 23:05

Lord Midi


People also ask

What is string XML file in Android?

String. xml file contains all the strings which will be used frequently in Android project. String. xml file present in the values folder which is sub folder of res folder in project structure.In Android Studio, we have many Views such as TextView,Button,EditText,CheckBox,RadioButton etc.

Why do we use string XML in Android?

xml , you can easily translate your whole app into other languages. This saves you a lot of work instead of doing this the hardcoded way: Android automatically selects the correct language based on user preferences, and you don't have to worry about selecting and displaying this language.

How do you put a space character in a string name in XML?

As already mentioned the correct way to have a space in an XML file is by using \u0020 which is the unicode character for a space.

Where is the strings XML file located?

Strings are typically stored in the resource file strings. xml . They are defined using a <string> XML element.


2 Answers

Easiest way is to quote or backslash them:

<string name="random">"?"</string>
<string name="random">\?</string>

See here and here for a bit more discussion.

  • ? reference styling attributes
  • @ signs access other resources.

Here's a larger collection of string resource gotchas.

like image 122
Dave Newton Avatar answered Oct 06 '22 06:10

Dave Newton


This is working for me:

<string name="twitter_hint">"@"twitter</string>
like image 25
Avinash Shinde Avatar answered Oct 06 '22 05:10

Avinash Shinde