I have a multiline EditText.
Whenever the input text is reaching its maximum width, the line breaks and the text is moving
to the next line.
However, it isn't working well with spaces.
When there is an input like "blabla" and then lots of spaces, the line not breaks and the text
is being pushed to the left until it "goes out" of the EditText.
How can I treat the spaces as "regular" characters for it to work?
thanks!
my suggestion convert it to html plain text. i mean
edittext.settext(Html.fromhtml(your text));
i hope it will help you...
Do you want to replace all spaces by newline?
String test = "";
test = your_et.getText().toString();
test.replaceAll(" ", "\n");
your_et.setText(test);
Related
I have some text inside string of value folder in android studio and I want to give space between paragraph but I don't know how to do that ?
you can use \n for new line and add space by entering space
for example:
<string name="above_eightteen">I confirm that \n I am above 18 years and agree to all Age restriction disclaimer.</string>
and use this string value in your layout.
Most probably your text will be a straight line in the string.xml file. find out the point where a paragraph is starting or ending, and put "\n" before paragraph start or after paragraph end.
In my text view, I am setting the HTML text:
mTextView.setText(Html.fromHtml("THIS USEFUL INTERESTING HTML TEXT IS DISPLAYED IN ANDROID TEXT VIEW"));
The Text is displayed as below:
The long word at the end is breaking with a hyphen. I want the complete word to go into the next line instead. How can I achieve this? I need to use HTML text only. The text can be dynamic and has to scale across various display size and orientations, I cannot put newline char in the text.
I'd suggest you to use attribute android:ellipsize to prevent breaking up a word
Try this...it should work
mTextView.setText(Html.fromHtml("THIS USEFUL" +"<br/>"+ "INTERESTING HTML TEXT IS DISPLAYED IN ANDROID TEXT VIEW"));
How to have HTML New Line Feature in Android Text View? for more clarity
I am having trouble while displaying a string in textview
policyValTv.setText(": " +trimPolicyNo);
Problem is if the trimPolicyNo is a long string, then the textview(policyValTv) displays the whitespace but breaks the line and displays the actual string on the next line. How can I avoid this? I want to display all on one line but not keep singleLine = true. Please help
Try with policyValTv.setText(":\u00A0" +trimPolicyNo); where \u00A0 is the unicode char for non breaking space.
Add to your textView in layout XML
android:maxLines="2"
android:ellipsize="end"
android:singleLine="false"
For some unknown reason, if I put the following string:
15 קמ
in a text view, it results in a new line between the "15" and the "קמ":
15
קמ
If I replace the "קמ" with "km" then it works fine...
Note: this doesn't happen if both string's parts are Hebrew.
Any clues?
I think that hebrew is interpreted RTL (right to left) while the other part is LTR (left to right). Given this, the TextView has to represent something like this:
\LTR 15 \RTL קמ
My logical guess is that the TextView puts the RTL part on a new line to deal with the nonsense of having both parts on the same line. If you force it all the way RTL when the locale is hebrew, I think it would regulate the rendering and solve the issue. I would suggest you try adding the "RIGHT-TO-LEFT MARK" character \u200F at the beginning of the string:
String text="15 קמ";
if (hebrew) {
text="\u200F"+text;
}
Also, it seems that some fonts are showing a graphical interpretation of the special character (while it shouldn't). You will probably need to use this font to get rid of it.
I have also experienced TextView alignment issue when I'm working with alphanumeric + arabic text in same text view, they will realign all the texts in left to right order which results ridiculous output. This kind of language issue is not really something we can fix in direct approach.
What we did were separating out the texts to more text views if applicable, which in your case I would suggest separating out the value and Hebrew text into separate TextView.
Try to use UTF-8 encoding for hebrew text, for eg:
String text = "15 קמ";
text = new String(text.getBytes(), "UTF-8");
If your textview can fit in one line, I think I might have a solution. This is the xml layout that did the trick.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="none"
android:text="15 קמ"
android:maxLines="1"
android:padding="8dp"
android:singleLine="true" />
Hey, Is it possible to specify a textview to have 25 characters in a line? I have tried android:maxLength="25" though it shows the first part of the text and the other part disappears.. Thanks
Edit1: I can also put the text into an EditText.. but I want that the characters that are after 25 chars, go to a new line..
http://developer.android.com/reference/android/widget/TextView.html#attr_android:maxLength
I am afraid, maxLength works for input EditText only. :-(
yes , sure android:maxLength="5" works for TextView to set the maximum number of characters for TextView. You can set android:layout_width="130dip" for the TextView too. That will show the character in the format abc... if the text exceed the layout width.