I have a text view that is showing a couple of characters as rectangles and I can't figure out where they are coming from. Any ideas?
Here is the XML with the text:
<item>
Five cents per gallon discount. Go online to www.amerigas.com or yellow pages for the closest AmeriGas location.
\n\n
Offers subject to change without notice, some restrictions may apply, contact store for details. Offer does not apply to fixed price customers. You must provide your Farm Bureau membership number to your AmeriGas dealer prior to delivery of your propane in order to receive the discount.\n
</item>
And here is a screenshot:
EDIT: In the XML, I notice when I paste it here the is a large space before Offers, which is where the characters are showing up. That space doesn't show up in my editor though.
My guess is that after the \n\n in the XML file, you have tab or some other odd white-space characters that the font does not handle correctly. Replace them with regular spaces and the little boxes should go away.
You need to replace the special char \n.
Just do this:
string = string.replace("\\\n", System.getProperty("line.separator"));
Related
I recently started getting translations into 5 languages for an app I'm working on. When I got the translated strings back, there were a bunch of extra lines added around any tags like <b> or xliff:g. In cases where the text before/after the tag was not a space (e.g. it was punctuation), the extra line causes Android to show an extra space. For example, consider the following string in English:
<string name="welcome_title">Welcome to <xliff:g id="app_name">App Name</xliff:g>!</string>
Pretty simple, right? When a TextView displays this in English, it obviously shows the desired result:
Welcome to App Name!
However, two separate translators (through the Play Store translation service) have now given me back translations that look like the following, e.g. in Spanish:
<string name="welcome_title">
Bienvenido a
<xliff:g id="app_name">App Name</xliff:g>
!
</string>
which causes a TextView displaying this text to show an extra space between "App Name" and the exclamation point:
Bienvenido a App Name !
Practically, this means I have to manually inspect/edit all of the thousands of lines of translations done for me to make sure there aren't extra spaces. Not only is it extremely annoying, but in cases like Arabic, I have no clue how correct any spacing is and it's really hard to know I'm editing correctly.
Has anyone come up with a way to prevent this from happening or clean it up quickly when it does happen? I couldn't find anything on this, but it's early and maybe I haven't had enough coffee! I can't be the only one who's had to deal with this.
I am trying to show a text in my android app using special unicode characters (Look like letters).
One character always is correspondending to tow unicode characters:
The first one is always '\uD83C' (55356) which is follwed by '\uDDF9' (56825) for 'A' for example (56826 for 'B' etc...). Setting the text generally works fine but whenever the text contains a substring which correpondens to a country encoding (Like 'ES' for Spain) it does not show the two characters but the flag instead.
I already tried to understand this behaviour and searched for possibilites to turn i did not find any soloutions
Example:
I want to show these characters: 🇹🇪🇸🇹
String value as char array:
Result in my TextView:
Can you help me find a way to disable this behaviour. I already seen it working in other apps.
The characters you are using only exist to produce flag emoji; they serve no other purpose and are not intended to be used for “fancy” text. Displaying flags for valid region codes is their only correct behaviour.
If you absolutely have to use them without that happening, you need to insert invisible characters inbetween every letter to break up the ligatures, for example U+200C (Zero Width Non-Joiner) or U+2060 (Word Joiner).
Folks,
In my social networking application, single-line messages come from various users. As the message comes in, I need to display them in our UI as a single line that shows the time, the user, and the message line. All 3 fields need to be colored differently.
I tried to use TextView but am running into a problem. As I need various colors, I thought of using SpannableString but the problem is that TextView.Append does not support SpannableString as a parameter.
The other thought I had was to build html style text as each line comes in.
I am wondering if I am overlooking something. Perhaps there is a better user control or a better way to achieve my objective.
Thank you in advance for your help.
Regards,
Peter
Use Html and with help of <font color><font/> tag, you can set single text with different color#
String result="<font color=color_code>First Textview</font> <font color=color_code>Second Textview</font><font color=color_code>Third TextView</font>";
textview.setText(Html.fromHtml(result));
You should use three different text fields, nest them in a table layout using columns, or a relative layout. That way they will automatically resize no matter what length.
You can also use the android:weight tag to control how much room each one takes up.
The reason is that usually its 1 label per field in data structure. As per MVC software design pattern.
In my application I need to add some string to a list and print them back. Problem is when I print them I can see the letters has inter change whithing the word.The word is in Arabic. (before 4.2 android doesnt support natively for Arabic).
What I tried was using several Arabic rendering classes such as fursi class and Arabi utility class. Nothing is helped me.
Here is the word ٣.. ما زاد على actually this part ٣.. should be the first it always goes to right as I have shown. Is there way to solve this thing. this is the one and only bug to hold the application to add to market :(
Oh, ouch! Arabic is worse than Hebrew in this aspect because Arabic has its own digits! Right!
I once had a similar problem on Windows, with symbols that weren't treated exactly as Hebrew but also not exactly as non-Hebrew. The only way I found to fix this was to split the string into two - print the problematic symbols (your 300) and then print the rest of the string.
I thought that with Unicode things has gotten better. I guess not always.
UPDATE: In a comment you said the translation of the string was 3.. . In Arabic, zero and a dot look very similar (which is why I confused a dot with a zero). Perhaps the person responsible of the input typed it wrong, not being fluent in Arabic, as well? 3.. doesn't make a lot of sense (3. does, and so does 300, but 3.. ?). Check the input, it might be wrong, and that can confuse the layout algorithm.
I can't technically understand the reason behind my action to correct above issue. However this is it . ` I reverse the word and separated letters by "+" and added to the list.It is amazing !
My app shows a variety of messages and in these messages, some parts have colour spans (e.g. ForegroundColorSpan) added to them so they are a different colour from the rest of the message. Currently, they are all hardcoded and because they are hardcoded, I know exactly where to start and end the span for the block of text I want to colour differently.
The problem I'm having is once I localize the messages, I can't figure out how to detect where a span should start and end. For example:
Hardcoded:
'x changed the topic to oh hai' - I know from char 23 to the end should have the colour changed.
Localized to Dutch:
'x veranderde het onderwerp te oh hai' - char 23 is something else.
(This is a trival example, some of the messages have colours in multiple locations)
So my question is, how can I, after localizing, still know where to start and end a span?
I would say it's not possible. How do you want to know about the grammatic, vocabulary of a language, what the translator decided was suitable...
But you can insert markers in your translations - lile ##, ##, or whatever, to indicate these blocks. Then you parse, catch the positions of these markers and use that for the spans.
I decided to make the strings one single colour than do some complex parsing.