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...
Related
I have to use some HTML tags inside a string.
The problem is that I can't use Html.FromHtml because the string is in strings.xml file for multi-language, so I should use the tags directly, but only </b>, </i> and <u> works and I need </h5> and </p>.
This is the string:
<string name="test">This is a test</string>
You can use CDATA in strings.xml to get all supported html tags.
<string name="stringName1"><![CDATA[<html>Some Text<h5>Some H5 Text</h5></html>]]></string>
In main activity
Use
textviewid.setText(html.fromHtml(getString(R.String.stringname)));
to get the data in the textview
I am using takephoto_library for selecting multiple images.
https://github.com/crazycodeboy/TakePhoto
It is working properly but as you can see in the below screenshot, the caption is in Chinese.
I found that the view control is "com.darsh.multipleimageselect.activities" and Id of this caption is in the below
actionBar.setTitle(R.string.album_view);
Is there any way to change this string to English?
Is there any way to change this string to English?
Yes, you can change all the Strings in strings.xml
https://github.com/crazycodeboy/TakePhoto/blob/master/takephoto_library/src/main/res/values/strings.xml
Change these two chinese word to english
<string name="add">确定</string>
<string name="selected">已选</string>
In English
<string name="add">confirm</string>
<string name="selected">selected</string>
Try this .
find the strings.xml(values) and strings.xml(values-en) in the library of TakePhoto .
And change the string name to the English .
In the strings.xml(values)
string name="add">确定</string>
<string name="selected">已选</string>
<string name="limit_exceeded">最多能选 %d 张</string>
And add this to the strings.xml(values-en)
string name="add">confirm</string>
<string name="selected">selected</string>
<string name="limit_exceeded">You can choose%d at most</string>
And you can change this strings.xml(values-en) and strings.xml(values)
For internationalization, android looks in different directories for the appropriate local as determined by your selection for the phone. For instance, you should see something like this:
./explorer/src/main/res/values-uk/strings.xml
./explorer/src/main/res/values-tr/strings.xml
./explorer/src/main/res/values-ru/strings.xml
./explorer/src/main/res/values-pl/strings.xml
./explorer/src/main/res/values-de/strings.xml
./explorer/src/main/res/values-ko/strings.xml
./explorer/src/main/res/values-sv/strings.xml
...
Where the translated strings are in the values-../strings as determined by the res/values/strings.xml.
In my case, res/values/strings.xml has an entry:
<string name="createnewfolder">Create new folder</string>
which is translated in values-uk/strings.xml as
<string name="createnewfolder">Нова папка</string>
You might find Localizing with Resources useful.
In my Android app I'm using strings.xml for all texts. I have many situations where I use almost the same string,
e.g. "Name" and "Name:" - translation is the same only additional colon is difference.
Is there any other way to have these two string except creating two string items like this:
<string name="name">Name</string>
<string name="name2">Name:</string>
There is no way you can concatenate strings in the strings.xml file.
All you can do is specify the format,
<string name="name">Name</string>
<string name="string_with_colon">%s:</string>
Then pass the name programatically,
String.format(getString(R.string.string_with_colon), getString(R.string.name));
Yes, you can do so without writing any Java/Kotlin code, only XML by using this small library I created which does so at buildtime: https://github.com/LikeTheSalad/android-stem
Usage
Based on your example, you'd have to set your strings like this:
<string name="name">Name</string>
<string name="name2">${name}:</string>
And then after building your project, you'll get:
<!-- Auto generated during compilation -->
<string name="name2">Name:</string>
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 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