I am displaying Activity's Title from strings.xml file like this
setTitle(R.string.add_contact_title);
I have following string in strings.xml
<string name="add_contact_title">Anadir Contacto</string>
but i want to display title like Añadir Contacto instead of Anadir Contacto.
is there any way to do this within the strings.xml file rather than copying and pasting the characters from another source?
You can also use unicode using the \u escape sequence like this:
<string name="add_contact_title">A\u00F1adir Contacto</string>
See here for a list of common unicode latin characters: http://unicode-table.com/en/#latin-extended-b
You can use ñ
You can find all the HTML Special Characters in this page
Special Characters in Android & HTML
just replace the code where you want to put that character. :-)
Yes you can do that. You have to start the special character with &
i.e for your case it will be like ñ
<string name="add_contact_title">Añadir Contacto</string>
Just check the link which will convert ASCII into Unicode
ASCII to Unicode
and Unicode Reference
Related
I have the following unicode character that I want to use in a string: 🚕
I have found its hex and decimal code through this:
While I know how to use the "&" symbol in a string in strings.xml by doing this:
<string name="Example">Example character &</string>
I cannot use the car symbol.
How can I use this unicode character in a string in strings.xml?
Update One:
Following the first solution of using this: 🚗
I got the following error:ERROR IN APPLICATION: input is not valid Modified UTF-8:
It's
<string name="Example">Example character \u0026</string>
See more unicode characters here:
http://www.utf8-chartable.de/unicode-utf8-table.pl?number=1024&utf8=0x
if you go Unicode site : https://unicode-table.com/en/#control-character and click at this Unicode that says U+00AE you mustn't write the + symbol if you want copy paste this example at strings.xml
:) :) :)
<string name="example">"\u00AE"</string>
Few important Unicode symbols for android strings.xml
<string name=”Rs”>\u20B9</string>
<string name=”filled_bullet”>\u25CF</string>
<string name=”linear_bullet”>\u25CB</string>
<string name=”rect_bullet”>\u25A0</string>
<string name=”blank_rect”>\u25A1</string>
<string name=”true_tick”>\u2713</string>
<string name=”star”>\u2605</string>
Full link is here
<string name="ic_happy_font"></string>
or
<string name="edit">🚕</string>
Check that the XML is in UTF-8 and has <?xml ... encoding="UTF-8"?> or defaulted <?xml ... ?>.
First the Unicode code point is U+1F695 which is decimally 128661 (not ...3).
In XML content your approach is basically correct.
🚕
🚕
The error mentions "modified" UTF-8. This just means the code point U+0000, a binary 0, is also encoded as multi-byte sequence of bytes with high bit set. This is support for C where a "string" ends on a NUL byte.
As the TAXI code point needs 4 UTF-8 bytes, it might be that the XML on Android only supports less long UTF-8 sequences. At least for numeric entities &#...;.
If the entities are a problem, use an UTF-8 capable editor and paste the TAXI from the clipboard.
You might try whether there is a work-around, whether u-escaped chars are read (probably not):
\uD83D\uDE95
A last wild attempt would be to use
<?xml version="1.1" ...
I think the code point you have in your example is an ellipsis. As per this page, try
🚗
If anyone gets underlined space although you didn't intent it, you can avoid this by using unicode code point of space
For example:
<string name="conditions">By signing in you agree to our <u>Terms &
Conditions.</u></string>
would also underline space before 'Terms & Conditions'
solution:
<string name="conditions">By signing in you agree to our\u0020<u>Terms &
Conditions.</u></string>
I have got the problem, that I can't display special characters like 'ß, ö, ä, ü' in my app.
The result is like this:
Or like this:
In Android Studio I get no error or warning and I am using the windows-1251 encoding.
In gradle I added this line: compileOptions.encoding = 'windows-1251'
It shall be german encoding.
How to fix that?
I actually can change special characters like 'ß' from predefined Strings with Html.fromHtml( unicode of the special character) like Html.fromHtml ( "ß" )
But what if a non predefined String contains a special Character? I have tried to simple replace the special character like this:
String neuer_String = get_street_adress.replace ( "ß", Html.fromHtml ( "ß" ) ) ;
straße.setText ( "Stra" + Html.fromHtml ( "ß" ) + "e: " + neuer_String);
But this doesn't work, because the string FriedhofstraÃe for example should be Friedhofstraße. So there is no character 'ß' in the string.
I also tried to change the font with Typeface but a exception is thrown: "native typeface cannot be made"
It's probably 'cause of the font in your device.
The way you can resolve this is by coding a Typeface out of a working font that you have tested.(e.g in Word,etc)
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/theNameOfTheFont.ttf");
Remember to place the code in fonts folder in assets. If you don't have one, create it.
Using UTF-8 encoding "might" solve your problem.
It's strongly recommended to use UTF-8 encoding.
With UTF-8 encoding, you can easily use the unicode value in your string.xml.
Here the a Link to XML character Entities List.
For example for ß use <string name="text szlig">text ß</string>
Go to the settings of Android Studio. In the File Encoding tab, make everything be formatted as UTF-8.
If the problem still persists, then the problem is in the font you are using as it may not support special characters.
I have found a solution for your problem, check it:
You can save all your strings with special characters in your strings.xml like:
<resources>
<string name="street">Straße</string>
</resources>
Then retrieve them in code like:
String street = getResources().getString(R.string.street);
You can definitely try other german characters out. Hope that works for you!
I am using WebView to display the String resource. Here is the code-
<string name="abc">à</string>
<string name="abcd">è</string>
When i load this in my webView it displays some garbage values. How to display this special characters in a WebView??
Check this list of special characters and how to encode in html.
<string name="abc">à</string>
<string name="abc">è</string>
If you enter these values into your values XML file using the graphical interface, the IDE will automatically format them for you.
Put symbol code in string tag:
<string name="welcome">Welcome !</string>
Output will be look like:
Welcome !
For more symbol code use below link :
http://www.degraeve.com/reference/specialcharacters.php
Enjoy...
How would one use an # symbol inside a string in strings.xml?
<string name="twitter">#npike</string>
The XML editor gets rather angry:
error: Error: No resource type specified (at 'twitter' with value '#npike').
Use this instead :
<string name="twitter">\#npike</string>
I would suggest use unicode like \u0040 instead of '#' symbol. XML processing doesn't like special symbols. Here is list of special characters and it's unicode valuesSpecial characters and unicode values
Try escaping it with a backslash "\#". That works for quotes. You can't use XML entities in strings.xml, otherwise I would recommend that.
While i'm retrieving data from remote server i'm getting some special
characters when i get known special characters i replaced them
with their original characters but when i don't no the
special characters how can i replace them? Some of the special
characters are as follows..
â €œ €™ € €“ â; ' & € ü Ü Û Ù
û ù Ø ß
Above are some them like this i'm getting some other . How to replace
these with their original characters in android.
It seems your question is how do you decode html encoded text?
Html.fromHtml(server_response).toString();
Html.fromHtml(server_response).toString();