How to use Swedish character å in string file in android - android

I have a Swedish word Pågår in my string XML file. When I try to read this word form the string resources it only shows P g r with å character missing in the output. Why is this happening and how can I solve this? Please help me in solving this error.

You can (should) escape special letters with the utf-8 representation for it.
Both \u00e5 and å would work for "å" in Android.
As requested, an example of localized fonts according to link.
To use localized Fonts, you can put the special fonts in assets and name it something like "se-font.ttf"
In your strings.xml for the Swedish language you add a value:
<string name="fontprefix">se-</string>
Then, in your app, when you load the font, you create the asset filename like so:
String fontasset = getString(R.string.fontprefix, "") + "font.ttf";
Then you should be able to load your font using the fontasset filename

in eclipse try to change the xml encoding: - Window->Preferences->XML->XML Files->Encoding
EDIT: And make sure that the font you are using support this character. (just remembered this one - Translate my app to Hungarian )

Related

I want to use some Arabic letters in card view as text in my android app

I want to use some Arabic letters in card view as text in my android app, how to achieve this. Anyone please help me.
Simply copy paste an Arabic string in your string.xml file. The access that string variable through resources. For example put this in your string.xml
<string name="message">هذا المجلد يات المحذوفة غير قابلة للإسترجاع.</string>
And put this in your code, now mystring variable should be Arabic.
String mystring = getResources().getString(R.string.message);
Read here and here more suggestions

display special character correctly

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 ( "&#223" )
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 ( "&#223" ) ) ;
straße.setText ( "Stra" + Html.fromHtml ( "&#223" ) + "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!

How can I put utf-16 characters in Android string resource?

I want to use Emojis in my app's strings. All strings reside, of course, in strings.xml
The problem is that not all Emojis are 16 bit friendly. Some Emojis can be represented as "normal" 16 bit hex: '\u26FF' but some are 32 bit hexes (UTF-16), usually represented as: '\x1F600'. I have no problem dealing with those inside the app, in code. But the strings.xml resource file is UTF8 encoded, and does not deal properly with non 16 bit escape chars.
I tried using '\x1F600' - because I saw that '\u26FF' works just fine. But it seems not to devour the 'x' escape char. Nor did it like the regexp notation '\x{1F600}'
So I ended up using a string placeholder '%1$s' and filling in the Emoji in code like this:
// greeting_3 is defined as: "hello there %1$s!"
String s = context.getString(R.string.greeting_3, "😜");
// OR:
String s = context.getString(R.string.greeting_3, new String(Character.toChars(0x1F61C)));
This is not a very elegant solution... is there a proper way to put 32 bit UTF-8 chars in strings.xml ?
But the strings.xml resource file is UTF8
If it's UTF-8 encoded, you can put your emojis directly. But then you risk that your editor or another piece of software destroys them.
If you are putting them in XML, you can try using XML entities: 😀, I'm not sure how well Android supports them though.
You can also use surrogate pairs: convert the emoji to UTF-16 and use standard \u escape. You can for example check out this page, it even tells you how to create a string litaral in Java: http://www.fileformat.info/info/unicode/char/1F600/index.htm
😜 → U+1F600 → "\uD83D\uDE00"
The easiest way it just copying and pasting the emoji, it works from Android Studio 3.0 and newer
Add the resource like follows:
<string name="string_title">This is a emoji example <U+1F642></string>
In Android Studio 3.0 you can copy and paste an emoji:
And here how it looks:

How to show Hindi text in android?

I am trying to paste Hindi characters in an array with elements like
String[] arr = {"आपका स्वागत है","आपका स्वागत है"};
but its giving error i.e.
"some characters cannot be mapped using "Cp1252" character encoding"
while saving this.
Switch your text encoding to UTF-8.
In Eclipse go to Window -> Preferences, select General -> Workspace. From the Text file encoding dropdown, select UTF-8.
Thanks i found the solution...
create an array under the value folder
Use the font that support Hindi under the assets folder
textview.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/Hindi.ttf")); its working fine...
You need UTF-8 encoding, not Cp1252, and Unicode.
Thanks i found the solution...
Create an array under the value folder
Use the font that support Hindi under the assets folder
textview.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/Hindi.ttf"));
its working fine...

writing some characters like '<' in an xml file

since the beginning of my programmation, I used some special character like "<-", ""<<" im my string.xml in Eclipse while developping for Android.
All worked fine for one year, but today, i just wanted to make some minor changes and began to edit my xml files.
I get now compilation error on these characters because eclipse believe it's part of the xml blocks.
Any idea on how I could add this symbol "<" in my xml files?
Thank a lot.
Use
< for <
> for >
& for &
Another way to insert special character follow Moss guide: How can I write character & in android strings.xml by used Unicode definition:
Example:
<string name="item_unknown">\u003c Item Unknown \u003e</string>
which present in string :
< Item Unknown >
I stumbled upon this question, as I use HTML markup in my strings.
If you refer to the Android String Resources documentation,
in the section:
"Styling with HTML markup"
you will see that in strings.xml, you need to use &amplt; for an opening bracket, but you can safely use backslash and a closing bracket. For example:
<b>Text</b>
can be written as:
<b>Text</b>
in your strings.xml.
If using this HTML string in your code, you can use:
Html.fromHtml( getResources().getString(R.string.yourHTMLString )
and the output will be your bold string!

Categories

Resources