TextView only displaying the first four lines of a resource string - android

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"

Related

Urdu language special character parentheses wrong displaying: right to left

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);

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.

Android TextView in ScrollView - Different color for each new line

I am creating sort of terminal-like view, that would display received and transmitted messages over Bluetooth,e.g. received messages in blue, transmitted in red.
So far, i managed to put textView inside scrollView and by using .append() methdod add lines to scroll view.
Layout looks like this:
<ScrollView
android:id="#+id/scrollingView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/disconnectButton"
android:layout_alignParentStart="true">
<TextView
android:text="Received and sent txt!!!\n"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollTextView"
android:minLines="11"
android:maxLines="11"/>
</ScrollView>
And code for adding text to scrollView:
scrollView = (ScrollView) findViewById(R.id.scrollingView);
scrollTextView = (TextView) findViewById(R.id.scrollTextView);
scrollTextView.setGravity(Gravity.BOTTOM); scrollTextView.setTextColor(getResources().getColor(R.color.receivedBTColor));
scrollTextView.append("$"+dataInPrint+"\n");
scrollView.fullScroll(View.FOCUS_DOWN);
The problem is that each of the lines should be able to be in different colors. setTextColor() method sets color for whole textView, which is totaly not what i want since i need to temporarily save the lines which go upwards until scrollView overflows. I looked at the example of using Spannable class, but it is quite messy.
Could anyone suggest a way to make a scrollable colorful text? Something like this?
Example from Bluetooth terminal app
Thanks a lot!
You can do a little tricky editing utilizing HTML and Android's Html.fromHtml()...
String dataInPrint = "" //Whatever the output message is.
String redB = "<font color="red">";
String blueB = "<font color="blue">";
String colorEnd = "</font>";
if(//message is send){
yourtextview.append(Html.fromHtml(redB + dataInPrint + colorEnd));
}
else{//message is recieve
yourtextview.append(Html.fromHtml(blueB + dataInPrint + colorEnd));
}

Optimizing Android app for blind people [duplicate]

I am developing an accessible android application where people would be using Explore by Touch and TalkBack accessibility services to use my application.
This is my Android XML code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/forename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="15dip"
android:textSize="20sp"
android:text="#string/forenameText"
android:contentDescription="#null"/>
<EditText
android:id="#+id/EditTextForename"
android:layout_width="285dp"
android:layout_height="65dp"
android:layout_marginTop="10dip"
android:layout_marginLeft="15dip"
android:hint="#string/forenameHint"
android:inputType="textPersonName"
android:lines="1"
android:singleLine="true"
android:textSize="20sp" >
</EditText>
</LinearLayout>
strings.xml
<string name="forenameText">Forename</string>
<string name="forenameHint">Enter your forename here</string>
TextView displays the title "Forename" and EditText allows me to enter some details in the form field. The problem I have is that when I
drag my finger across the screen by using Explore by Touch, TalkBack picks up the title of the TextView and announces it aloud as "Forename". I want the TextView to only display text and not provide any audible feedback.
I have set contentDescription to #null as you can see from the code above, but TalkBack still announces "Forename" when my finger is located over the
TextView.
I have also tried setting contentDescription in my Java class:
TextView forename=(TextView)findViewById(R.id.forename);
forename.setContentDescription("");
However, I still get the same problem. Is there any other way to set contentDescription to null/empty and prevent TalkBack from announcing it aloud?
Java code:
public class MainActivity extends Activity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View forename = findViewById(R.id.forename);
forename.setAccessibilityDelegate(new AccessibilityDelegate() {
public boolean performAccessibilityAction (View host, int action, Bundle args){
return true;
}
});
}
}
Since API 16, Android introduced the following:
android:importantForAccessibility="no"
or
setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO)
Which allows developers to disable talkback all together for certain views.
http://developer.android.com/reference/android/view/View.html
For better backwards compatibility:
ViewCompat.setImportantForAccessibility(
decorativeTextView,
ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO);
I was trying to do the same today, and was able to set an 'empty' contentDescription on a TextView like so (using a non-breaking whitespace):
decorativeTextView.setContentDescription("\u00A0");
now TalkBack doesn't say anything for that TextView.
but I agree with Nick about leaving the label as readable in your case, because hint is only read for empty EditTexts.
Why do you not want the TextView to speak "forename"? It is being used as a label for the EditText. Once the user has entered some text the hint "enter your forename here" would no longer be spoken - as far as I know - so the TextView given the user some context for the EditText.
Similarly the announcement of "editbox" gives the user the role of the EditText control. While "form field" might be better it would not be the same behavior as in other apps and in the OS.
I had a similar problem. I eventually solved it by using the setAccessibilityDelegate method and overriding View.AccessibilityDelegate's performAccessibilityAction method.
try this:
View forename = findViewById(R.id.forename);
forename.setAccessibilityDelegate(new AccessibilityDelegate() {
public boolean performAccessibilityAction (View host, int action, Bundle args){
return true;
}
});
I had the same problem, and the only thing that worked for me was android:contentDescription=" " (white space).

Android - prevent TalkBack from announcing TextView title aloud

I am developing an accessible android application where people would be using Explore by Touch and TalkBack accessibility services to use my application.
This is my Android XML code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/forename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="15dip"
android:textSize="20sp"
android:text="#string/forenameText"
android:contentDescription="#null"/>
<EditText
android:id="#+id/EditTextForename"
android:layout_width="285dp"
android:layout_height="65dp"
android:layout_marginTop="10dip"
android:layout_marginLeft="15dip"
android:hint="#string/forenameHint"
android:inputType="textPersonName"
android:lines="1"
android:singleLine="true"
android:textSize="20sp" >
</EditText>
</LinearLayout>
strings.xml
<string name="forenameText">Forename</string>
<string name="forenameHint">Enter your forename here</string>
TextView displays the title "Forename" and EditText allows me to enter some details in the form field. The problem I have is that when I
drag my finger across the screen by using Explore by Touch, TalkBack picks up the title of the TextView and announces it aloud as "Forename". I want the TextView to only display text and not provide any audible feedback.
I have set contentDescription to #null as you can see from the code above, but TalkBack still announces "Forename" when my finger is located over the
TextView.
I have also tried setting contentDescription in my Java class:
TextView forename=(TextView)findViewById(R.id.forename);
forename.setContentDescription("");
However, I still get the same problem. Is there any other way to set contentDescription to null/empty and prevent TalkBack from announcing it aloud?
Java code:
public class MainActivity extends Activity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View forename = findViewById(R.id.forename);
forename.setAccessibilityDelegate(new AccessibilityDelegate() {
public boolean performAccessibilityAction (View host, int action, Bundle args){
return true;
}
});
}
}
Since API 16, Android introduced the following:
android:importantForAccessibility="no"
or
setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO)
Which allows developers to disable talkback all together for certain views.
http://developer.android.com/reference/android/view/View.html
For better backwards compatibility:
ViewCompat.setImportantForAccessibility(
decorativeTextView,
ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO);
I was trying to do the same today, and was able to set an 'empty' contentDescription on a TextView like so (using a non-breaking whitespace):
decorativeTextView.setContentDescription("\u00A0");
now TalkBack doesn't say anything for that TextView.
but I agree with Nick about leaving the label as readable in your case, because hint is only read for empty EditTexts.
Why do you not want the TextView to speak "forename"? It is being used as a label for the EditText. Once the user has entered some text the hint "enter your forename here" would no longer be spoken - as far as I know - so the TextView given the user some context for the EditText.
Similarly the announcement of "editbox" gives the user the role of the EditText control. While "form field" might be better it would not be the same behavior as in other apps and in the OS.
I had a similar problem. I eventually solved it by using the setAccessibilityDelegate method and overriding View.AccessibilityDelegate's performAccessibilityAction method.
try this:
View forename = findViewById(R.id.forename);
forename.setAccessibilityDelegate(new AccessibilityDelegate() {
public boolean performAccessibilityAction (View host, int action, Bundle args){
return true;
}
});
I had the same problem, and the only thing that worked for me was android:contentDescription=" " (white space).

Categories

Resources