I would like to display some text in a TextView, but I would like to avoid text wrapping in a specific position of the text, to avoid the text to display like this:
This is my very long text
:
Instead, I want my text to display as following:
This is my very long
text :
You may ask: why is there a space before :?
Simply because it's in French, and, unlike English, you're supposed to add an extra space before this character (also available with ? and !).
I tried this:
TextView myTextView = (TextView) findViewById(R.id.my_text);
myTextView.setText(Html.fromHtml("This is my very long <span style=\"white-space: nowrap;\">text :</span>"));
But of course, it doesn't work.
I was also thinking of a specific character that behaves like a space but without wrapping. I don't know if it exists, and if it's a good practice.
I finally found out a solution for the specific white space wrapping problem: just add \u202F instead of your white space in your string, like for example:
<string name="my_string">This is my very long text\u202F:</string>
Related
I have a TextView and I set text which I receive from Backend.
the text is either from 1 to 3 words.
Maximum the textview can be 2 lines.
I am using setAutoSizeTextTypeUniformWithConfiguration
and text.breakStrategy = LineBreaker.BREAK_STRATEGY_SIMPLE
And I don't have any success.
wondering is it possible if the text is single word I don't want to split it. I would like to have it in single line with small textSize. if the text is 2 words and long I am fine to show it in 2 lines. The problem is it always breaks the word in 2 lines if it is long while I don't want.
The only solution that comes to my mind is before setting the text to a textview, check whether text has spaces in it.
If it has not that that means it's a single word, so set ptogrammatically maxlines to 1, otherwise set maxlines to 2.
EDIT: I missed text size part. I use this library for autoresizing and it worked so far https://github.com/jivimberg/AutoResizeTextView
it's automatically handled in androidx.appcompat.widget.AppCompatEditText and just set android:maxLines="2"
remove all other properties you set
I have a simple TextView, where I put a string like that: "Curăță corect urechile copilașului tău!". But I see the string on display like this "Cură ă corect urechile copilașului tău!" - just space between chars, where must be a "ț" symbol.
I checked the string in TextView by TextView.getText(), and I get my original string.
This is a screenshot, also the same problem in first title:
Try to set text in TextView using HTML. I hope this will work and may help you out.
myTextView.setText(Html.fromHtml("your_string"));
There is still space for the letters, so perhaps it's an issue with the styling.
Change the style to default, do the letters show up?
Try adding a shadow to the textviews and see if the shadow exists (maybe the letters are somehow transparent, or the same color as the background?)
It is more related to a font issue, default Android font doesn't support some characters. You need to try from a different font.
You can try from the following (but I think its not free)
http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=FontDownloads
I want to Justify the text into textView. I does not want to use web view. because i can't increase the text size at run time for different screens. So I want To use the text view.
I want some things like that.
You can set HTML on a TextView.
So...
String htmlString = "<p align=\"justify\">This is some text in a paragraph.</p>";
mTextView.setText(Html.fromHtml(htmlString));
Good Luck. :)
I have a long string, with multiple bold words inside the string.
The styling of the non bold sentences are done inside the TextView XML part and this is looking fine.
But i want to make the bold words bigger and thicker.
Is this possible to change this with XML?
for example:
<string name="long_text">This should be a <b>long</b> text with different <b>styling</b></string>
The bold words are supposed to be 1.5 times bigger
Or should i do this in the Java code?
yes you have to do this in java because there is no way to as per your requirement,
you can use TextAppearanceSpan in java code with Spannable
if i am getting you right than try the following..
textview.setText(Html.fromHtml(getResources().getString(R.string.long_text)));
Mark as right if it works for you .
I have an listview and I need help with it. I'd like to keep the text in one "row" if would call it that.
So what I mean is, it doesnt matter how long the text is, if it's longer than the "witdh" then instead of showing the full text on two "rows" it should just fill that witdh and like, end it with ... or something else. The purpose of this is ofcourse so that all my rows in the listview are of the same size, or else it looks rlly amateurish and cheap ..
How can I do this?
Thanks for help!
Give the TextView that holds the long text following attributes
android:ellipsize="end"
android:singleLine="true"
This will ensure that long text is displayed in a single line end with "..." at the end.
Found in android doc: http://developer.android.com/reference/android/widget/TextView.html#attr_android:ellipsize