How to set the length of text in a button

I want to have a fixed size button

If the text is longer than the width of the button, it should show "tex ..."

How to do it?

+3
source share
4 answers

You can use Ellipsize, but there is an error. The workaround is to set scrollHorizontally to true and lines to 1. See the following code example:

<Button android:text="Button"
    android:layout_width="50dp"
    android:layout_height="wrap_content"
    android:scrollHorizontally="true" 
    android:lines="1"
    android:ellipsize="end">
</Button>
+6
source

Please try entering the code in the button

android:maxLength="5"
0
source

aString.length();, , , , aString = aString.substring(0, aString.length() - int); , int aString.length() - , . ... aString.append( "..." );

0

Use a text box instead of a button and use the ellipsize property to get 3 dots. You will also need to listen to the click in text mode so that it functions as a button.

You will also need to use: android: scrollHorizontally = "true" for the appearance of "..." (error in android :-()

0
source

All Articles