android toast 不适合文本
我正在开发一个应用程序,我必须使用大量的吐司。
我通过使用以下方式显示这些 toast:
Toast.makeText(context, "Some medium-sized text", Toast.LENGTH_SHORT).show();
但是,显示器 toast 的高度为一行,而文本显示在多行上。结果是我无法查看toast中的所有文本。
我该如何解决这个问题?
I am developing an application where I have to use numerous toasts.
I display these toasts by using:
Toast.makeText(context, "Some medium-sized text", Toast.LENGTH_SHORT).show();
The displayer toast, however, has the height of one line, while the text is displayed on multiple lines. The result is that I can't view all the text in the toast.
How can I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在要拆分文本的位置插入回车符和换行符。
这些字符指的是旧打字机模型。回车是指气缸回到起点,换行是指气缸滚动(进给)一行。
在计算中,它们由两个转义字符表示(特殊代码,通过在字符串中添加反斜杠
\
前缀,允许在字符串中使用不可打印的代码)。\r
表示,\n
表示(您可以将其记为新行)。一些非 UNIX 系统(例如 Windows)需要两者,其他系统(例如 Android 所基于的 Linux)只需要换行符,但通常在任何地方都执行这两种操作是安全的。重要的一件事是它们的顺序。它必须是
\r\n
要将其放入您的示例中:
在 Android 中,您应该能够将其减少为新行字符 < code>\n 因为基于 UNIX 的系统并不那么挑剔:
Try inserting a carriage-return and line-feed where you want to split the text.
These characters refer back to the old typewriter models. Carriage return was the cylinder moving back to the start and line feed was the cylinder rolling (feeding) by one line.
In computing these are represented by two escaped characters (special codes that allow non-printable codes inside a string by prefixing them with a backslash
\
).\r
\n
(you can remember this as a new line).Some non-unix systems (e.g. Windows) require both, others (e.g Linux on which Android is based) only need the new line but it is generally safe to do both everywhere. The one thing that is essential is the order they are in. It must be
\r\n
To put this into your example:
In Android you should be able to reduce this to just the new line character
\n
as unix based systems are not so fussy:使用这个Android中的自定义toast:一个简单的例子的主要思想和这个 Android 的 Toast 默认颜色和 alpha 我开发了一个简单的自定义Toast 看起来与默认的 Toast 类似,但它将文本包裹在多行中。
我使用
makeText(context,text,duration)
静态方法创建了一个简单的类,因此我只需将Toast.makeText
替换为CustomToast.makeText
code> 在我的项目中随处可见。代码下方
CustomToast.java
布局
layout/custom_toast.xml
Using the main idea of this Custom toast in android : a simple example and this Android's Toast default colors and alpha I developed a simple custom Toast that looks like the default one but it wraps the text in multilines.
I create a simple class with the
makeText(context,text,duration)
static method, so I had only to replaceToast.makeText
withCustomToast.makeText
everywhere in my projects.Below the code
CustomToast.java
The layout
layout/custom_toast.xml