如何在按钮上显示多行文本 [英] how can I display multiple lines of text on a button

查看:29
本文介绍了如何在按钮上显示多行文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的按钮的 layout_width 设置为 match_parent.

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 将 Maxlines 设置为 2 或 3

set Singleline false set Maxlines to 2 or 3

从 Html.fromHtml 转换 html

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.

推荐答案

如果您尝试在布局 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.

这篇关于如何在按钮上显示多行文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆