Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

android - how can I display multiple lines of text on a button

My button's layout_width set to match_parent.

In order to display multi lines on the button, I tried:

  • insert ' ' into the text on button

  • set Singleline false set Maxlines to 2 or 3

  • convert html from Html.fromHtml

Nothing worked. ' ' showed up as a small square on the button while showing single line of text.

Does anybody have any idea why this is happening and how I can fix this?

UPDATE: I just found out I was using custom button that has its own text drawing. That's the reason. Sorry for the confusion. I just punished myself by banging my head.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you're trying to add a new line in a layout XML file:

Use 
 (new line)

    android:text="Hi
Hello"

If you're trying to add a new line in code, just use ' ', same as in any other text.

If you can't see the second line, it may be that your Button doesn't have enough height. IE, in my case, the layout containing the button had a fixed height that just happened to make my button perfectly display one line of text.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...