Urdu language special character parentheses wrong displaying: right to left - android

I am trying to display an Urdu text (Right to Left) in my app android HtmlTextView of the following dependency org.sufficientlysecure.htmltextview, but I get parentheses wrong displayed left to right in lines.
In the above image, parentheses display wrong formatting even though I checked the text is proper.
and below the image is the correct version of the text
Here is my XML code
<org.sufficientlysecure.htmltextview.HtmlTextView
android:id="#+id/detail_d"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/_8sdp"
android:layout_marginRight="#dimen/_8sdp"
android:gravity="right"
android:paddingLeft="#dimen/_1sdp"
android:paddingRight="#dimen/_1sdp"
android:text="#string/urdu_detail"
android:textColor="#000"
android:textIsSelectable="true"
android:textSize="#dimen/_18ssp" />
Here is my Java code
private String htmlText = "سنبل کی لہر سے نہ رہے پھر ہمیں مطلب یکدست جو تم کا کل خمدار دکھاؤ (١٨٤٠ء، کلیات ظفر، ١٩٣:١)<br>";
private HtmlTextView htmlTextView = htmlTextView.setHtml(htmlText);

Related

How do I set phone numbers to be LTR in a RTL TextView with RTL characters

As you can see here, the phone number here is starting from the right to the left.
However, I want it to display it like this (Image here is edited):
This is the TextView displaying this message:
<TextView
android:text="#string/smsSentTo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/smsSentTo"
android:textColor="#color/mdtp_white"
android:textSize="18sp"
android:layout_above="#+id/chooseUsernameAndPickProfilePicture"
android:layout_centerHorizontal="true"
android:layout_marginBottom="24dp"/>
#string/smsSentTo (Arabic locale): (looks like StackOverflow is displaying the {0} wrong, ignore that.)
<string name="smsSentTo">تم إرسال رسالة SMS إلى {0}</string>
#string/smsSentTo (English locale):
<string name="smsSentTo">An SMS has been sent to {0}</string>
As you can see, I'm formatting the text using MessageFormat:
String smsSentTo = MessageFormat.format(smsSentToTV.getText().toString(), phone);
smsSentToTV.setText(smsSentTo);
How can I get it to display these properly?
There is a solution with a downside
String html = "<p>تم إرسال رسالة SMS إلي</p>" + "+961 01 234 567";
textView.setText(Html.fromHtml(html));
The downside is that the HTML p tag prints a line afterwards separating the number into the next line. I tried to remove it with some HTML attributes or using tags other than p tag, but that didn't work
Hope this satisfies your need, or can give you even a clue.

Override TextView ellipsize char('...') with ("... Read more")

I want to replace the char ('...') with a string ("...Read more").
Any easy way to do that by extending TextView and overriding a property?
I am expanding the TextView on click by increasing lines from 2 to 500 and vice versa. The TextView is in a ScrollView.
This code is XML File.
<com.google.android.material.textview.MaterialTextView
android:id="#+id/textDescriptions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="What is Android ? \nBefore learning all topics of android, it is required to know what is android.Android is a software package and linux based operating system for mobile devices such as tablet computers and smartphones." />
This code is Java file.
String readMore = "... Read more";
String shortDescription = textDescriptions.getText().toString().substring(0, 100);
String text = "<font color=#aaaaaa>"+shortDescription+"</font> <font color=#ff669900>"+readMore+"</font>";
textDescriptions.setText(Html.fromHtml(text));

Android TextView ellipsize error with Html Text

I have some problem with ellipsize in TextView.
Here is html string:
final String str = "His followed carriage proposal entrance <br/>directly had elegance. Greater for cottage gay parties natural. Remaining he furniture on he discourse suspected perpetual. <br/>Power dried her taken place day ought the. Four and our ham west miss."
I create 2 textview(tv_test_html, tv_test_normal).
<TextView
android:id="#+id/tv_test_html"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLines="3"
android:ellipsize="end"
android:text="Hello"
/>
<TextView
android:layout_marginTop="20dp"
android:id="#+id/tv_test_normal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLines="3"
android:ellipsize="end"
android:text="Hello"
/>
In code I set:
final TextView tvTestHtml = (TextView) findViewById(R.id.tv_test_html);
final TextView tvTestNormal = (TextView) findViewById(R.id.tv_test_normal);
tvTestHtml.setText(Html.fromHtml(str));
tvTestNormal.setText(str);
When I run application:
You can see "..." is error when I use Html.fromHtml(...);
So how do I fix it ?
Thanks in advance !
[I just update image]
replace string with it : His followed carriage proposal entrance <br>directly had elegance. Greater for cottage gay parties natural. Remaining he furniture on he discourse suspected perpetual. <br>Power dried her taken place day ought the. Four and our ham west miss.

TextView only displaying the first four lines of a resource string

I'm having trouble displaying some text in a dialog. When the user has forgotten their password, I use the "forgot password" TextView to display a message explaining what happens when they put their email address in. The layout for this is:
<TextView
android:id="#+id/forgotpasswordtextview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/forgotpassword"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/md_text_yellow"
android:gravity="right" />
It's inside a <LinearLayout></LinearLayout> with the following properties:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/base_panel"
android:orientation="vertical"
android:padding="6dip" >
It starts as a one-line view and expands to a four-line view.
Within the dialog constructor, I have a layout instruction:
mParent = LayoutInflater.from(context).inflate(R.layout.login, null);
setContentView(mParent, new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
I changed this to have the dialog height be 600 (it worked—one vertically stretched dialog) and the TextView is STILL only displaying four lines, so it's not being crushed by its parent.
What could be causing this?
EDIT:
Changing the TextView to android:textAppearance="?android:attr/textAppearanceSmall" cuts the string off at the same point, displaying three lines. I am now wondering if this is a string problem and not a TextView problem.
The original string is:
Please enter your registered email and we will send you details of how to reset your password. If you do not know your email then please contact us.
And it cuts off at:
Please enter your registered email and we will send you details of how to reset your password. If you do not
with small text (three lines) and
Please enter your registered email and we will send you details of how to reset your password. If you do not know
with medium text (four lines).
A new test string I put in is:
0________ 1________ 2________ 3________ 4________ 5________ 6________ 7________ 8________ 9________ 10_______ 11_______ 12_______ 13_______ 14_______ 15_______ 16_______ 17_______
And it cuts off at:
0________ 1________ 2________ 3________ 4________ 5________ 6________ 7________ 8________ 9________ 10_______ 11_______ 12_______ 13_______ 14_______
with small text (five lines) and
0________ 1________ 2________ 3________ 4________ 5________ 6________ 7________ 8________ 9________ 10_______ 11_______
with medium text (six lines).
FURTHER EDIT:
Shortening the string suggests it is cutting off the last line or two. Could be like Android: Last line of textview cut off. Adding a newline to the string file gives me another line, but not the whole string!
Try to use the following attributes for your text view
android:maxLines="10"
android:ellipsize="none"
android:singleLine="false"

Android setting with TextView for Hebrew text?

I am setting text in TextView from string resource. Normally, Hebrew works in Right-To-Left format. When I set a text, it sets the text Right-To-Left format in LG, Samsung, Sony Phone but in HTC it does not work. It works in Left-To-Right format in HTC. Even I set Gravity to the TextView in Java file.
Text in TextView should be span according to the screen size. For example if it is 320 x 480 then it display in 4 lines but if it is Galaxy Tab then there may be 2 lines.
Here is my Code snippet:
In Java:
private TextView mVersionInfo, mVersionDescriptionOne, mVersionDescriptionTwo, mVersionDescriptionThree;
mVersionInfo = (TextView)findViewById(R.id.VersionInfo);
mVersionDescriptionOne = (TextView)findViewById(R.id.VersionDesc1);
mVersionDescriptionTwo = (TextView)findViewById(R.id.VersionDesc2);
mVersionDescriptionThree = (TextView)findViewById(R.id.VersionDesc3);
mVersionDescriptionOne.setGravity(Gravity.RIGHT);
mVersionDescriptionTwo.setGravity(Gravity.RIGHT);
mVersionDescriptionThree.setGravity(Gravity.RIGHT);
in XML:
<TextView android:id="#+id/VersionDesc1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="#string/versiondesc1" android:textColor="#000000"
android:layout_marginTop="5dip" android:gravity="right"
android:layout_alignParentRight="true" android:layout_marginRight="10dip"
android:layout_below="#+id/Share" android:textSize="13sp"
android:layout_alignRight="#+id/Body" />
<TextView android:id="#+id/VersionDesc2"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="#string/versiondesc2" android:textColor="#000000"
android:layout_alignParentRight="true" android:layout_marginRight="10dip"
android:layout_below="#+id/VersionDesc1" android:textSize="13sp"
android:layout_marginTop="5dip" android:gravity="right"
android:layout_alignRight="#+id/Body" />
<TextView android:id="#+id/VersionDesc3"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="#string/versiondesc3" android:textColor="#000000"
android:layout_alignParentRight="true" android:layout_marginRight="10dip"
android:layout_below="#+id/VersionDesc2" android:textSize="13sp"
android:layout_marginTop="5dip" android:gravity="right"
android:layout_alignRight="#+id/Body" />
In String Resource:
<string name="versiondesc1">האפליקציה מתחברת לאתר הספק הסלולרי כדי להציג את מצב החשבון. לעיתים, כשאתר הספק איננו עובד תקין לא יהיה ניתן לקבל מידע. באם אתר הספק ישתנה האפליקציה עלולה להפסיק לעבוד. במצב כזה האפליקציה תחזור לעבודה תקינה מיד לאחר שאנו נתאים את שרת התוכנה שלנו לשינויים.</string>
<string name="versiondesc2">הערה: אנחנו לא מייצגים את חברות הסלולר ולא נמצאים איתן בקשר מסוג כלשהו!</string>
<string name="versiondesc3">אם נתקלת בבעיה, השתמש/י בכפתור יצירת קשר על מנת שנוכל לפתור אותה. נשמח לקבל כל משוב על האפליקציה.</string>
What is wrong with my code?
Anybody who has worked with another language, Please guide me here.
Thanks.
Gravity will only affect alignment and will not set base direction for the text. That it works on some devices and not others may be a font issue, or perhaps an OS version issue. Try adding a RIGHT-TO-LEFT MARK character (\u200F) at the start of your text. This might help the display on an HTC and will not hurt anything on devices where it is already working.
here is an example from my hebrew string xml, Thanks to Ted Hopp's answer:
you need to add '\u200e' before the char that causes you the problem:
<string name="basic_text1">המר על תוצאת המשחק\u200e:</string>
and the result will be:
:המר על תוצאת המשחק

Categories

Resources