且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在按钮上显示多行文本

更新时间:2023-12-04 13:53:36

如果您尝试在布局 XML 文件中添加新行:

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

使用
(换行)

    android:text="Hi
Hello"

如果您想在代码中添加新行,只需使用 ",与在任何其他文本中一样.

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

如果您看不到第二行,可能是您的 Button 没有足够的高度.IE,在我的例子中,包含按钮的布局有一个固定的高度,正好让我的按钮完美地显示一行文本.

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.