you can extend the TextView class and overwrite the setText() function. In this function you check for text length or word cound. Better than counting the text length or the word cound a better way would be to use the "maxLines" attribute along with "ellipsize" attribute to attain the desired effect.
use an input filter to limit the max length of a text view. This is very useful if someone already made some InputFilter . It overrides android:maxlength in xml file, so we need to add LengthFilter this way.
To use preset sizes to set up the autosizing of TextView in XML, use the android namespace and set the following attributes: Set the autoSizeText attribute to either none or uniform. none is a default value and uniform lets TextView scale uniformly on horizontal and vertical axes.
setTextSize(float size) method to set the size of text. textView.
Use android:maxLength="12"
to limit the text length
<TextView
android:id="@+id/textViewName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/includeheadersetting"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="Name"
android:maxLength="12"
android:textColor="#000000"
android:textStyle="bold" />
You can also use another property as follows:
android:ellipsize="end"
android:maxLines="1"
Using this property "..." will be added end of the text as follows:
"Hello How are ..." instead of "Hello How are you?"
Generally speaking only including android:maxLength
is not considered good idea.
Use maxLength attribute, then use the android:ellipsize="marquee"
to add a "..." automatically to the end of any line that has been cut-off.
<TextView
android:id="@+id/txtView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:maxLength="10"
android:ellipsize="marquee"/>
add code like
android:maxLength="12"
Add the following max length parameter to your text view-
android:maxLength="12"
whatever the limit you want you can replace that like instead of 12 can give 14 or whatever length you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With