开发者

How to set text length in button

I want to have a fixed size button

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

H开发者_开发问答ow do I do this?


Ellipsize can be used but there is a bug. 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>


Please try below code in button

android:maxLength="5"


I'd use aString.length(); and if it is greater than whatever int you choose, shorten it with aString = aString.substring(0, aString.length() - int); and make that int aString.length() - the max length you want. then take the new string and append the ... with aString.append("...");


Use a textview instead of a button and use the ellipsize property to get the 3 dots. Also you will need to have a click listener on the textview to make it function as a button.

You will also need to use : android:scrollHorizontally="true" for the "..." to appear ( bug in android :-( )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜