Is there a way to create/override the custom word wrap engine for Android TextView?
For example,
My name is Edwin (US:1113)
Should be displayed as
My name is Edwin
(US:1113)
Instead of
My name is Edwin (US:
1113)
Already tried changing all the possible value for the setting below but nothing good.
Android:maxLines
Android:setHorizontallyScrolling
Android:ellipsize
Android:singleLine
In my findings, word wrap in TextView does not include special characters such as :.
Updated 3.09AM 2/7/2018 UTC
As mentioned by #Umair, line breaking with "\n" is not possible because I don't know the length of the text before the colon :. This will line break the sentence too early before it reached the maximum width of the TextView.
Use 2 TextViews inside a LinearLayout with horizontal orientation and put My name is Edwin in the 1st and (US:1113) in the 2nd. If there is no space for the 2nd TextView then it will fall to the next line.
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 want to get the number of characters which are visible in TextView when we have applied android:ellipsize in TextView. Suppose i have "This is dummy top stories title with multiline, This is dummy top stories title with multiline." text and i have set "android:ellipsize="end" android:maxLines="2"" these properties in my Textview , so it will cut down some text and show the 3 dots. Now i want the nuumber of characters which are visible.
In case of singleLine TextView:
stringLength - textView.length()
would give how much text is not shown or ellipsized away in device.
Same way in case of multiline TextView you can use:
Layout textViewLayout = textview.getLayout();
textViewLayout.getEllipsisCount(textViewLayout.getLineCount()-1)
As per Documentation at developer.android.com
getEllipsisCount(int line)
Returns the number of characters to be ellipsized away, or 0 if no ellipsis is to take place.
Note: getEllipsisCount must be used after textview is visible/drawn.
I have a textview with fixed height. I want to set a long text, but text comes at the last line getting cut by half, I want to avoid it and want to show a continuation symbol. I am giving an image here, I wan to achieve it like in the image.
Use the ellipsize attribute of TextView. By setting :
<TextView
....
android:ellipsize="end">
</TextView>
if the text is longer than your TextView you will have dots(...) at the end of the TextView.
Two line of string only possible to do like this. set ellipsize = end in text view properties.
you should use \n and special symbols from google code.
I have a TextView and my need is to add 10 characters in that TextView by code. But when characters are greater than 10, they should be display in TextView but with 8 character + .. of that charsequence. And when I want to read text of that TextView I must get full charsequence not 8 character + .. . For example
tv.settext("ASDFGHJKLQ") // this is 10 characters long, so no rule required
but
tv.settext("ASDFGHJKLOP") // this is more than 10 characters then it should be display as
ASDFGHJK.. in textView, but when I retrieve the value of textview, it should return ASDFGHJKLOP instead of ASDFGHJK.. , so how can it be done.
That textView is row of a listview.
Try adding this to your TextView (marquee or end):
android:ellipsize="marquee"
You may also need:
android:scrollHorizontally="true"
Without scrollHorizontally="true" you may still get the text wrapped rather than appended with ... I use these very 2 lines to display a list view in my app. The 3 long lines I have get appended correctly.
This truncating happens because it does not fit in your list item. Reduce the font ?
or ellipsize ?
I see only one solution. But maybe there are another solutions.
To store you string.
If string's length is greater than 10 letters set text of your TextView with 12345678..
And if you want to get right text you should take the value of the string and not of the textview.
in my custom listview that Contain an image and EditText ,and in EditText i can comment the photo ,i can give text comment max length of 50 ,when i lost the focus in EditText i want to rearrange the text in EditText in following format
EG: suppose comment contain 40 char and user can at a time directly view only 20 char,then if i lost the focus text should be rearranged that at the end there should be 3 dot
Original Comment i wirte:eg-> eeeeeeeeeeeeeeeeeeeeeeeeeee after i lost focus it should shown as-> eeeeeeeee...
it's importent that the nothing happens to original text because these text i want to send to server, and i directly take these values,and if am replace the text by new this type of text this will create problem, also when i gain focus i need to see full text also.
i have used this android:ellipsize="end"
You have to set a specific value for android:ems on your EditText if you want to use the ellipsize function as it will only truncate strings longer than the EditTexts width. With ems or maxEms you can specify how many ems wide your EditText should be. Also don't forget to set android:singleLine to true.