Toast.makeText(...).show() 有时会错位
我正在使用 Toast.makeText 显示对话框的结果,并遇到一个稍微奇怪的问题:文本显示在应该容纳它的框架上方,如下所示:
消息与框架未对齐。请更好地对齐。 [_______________< em>_________< em>_________________________]
我通常使用看起来像
Toast bread = Toast.makeText(getContext(), R.string.message, Toast.LENGTH_LONG);
bread.show();
对话框中的代码。我听说糟糕的上下文有时会导致通货膨胀问题,但 getOwnerActivity() 返回 null,所以这是不可能的。无论如何,我认为 getContext() 会提供在构造时传入的上下文,这无论如何都是活动。
有什么建议吗?
I am using Toast.makeText to display results from dialogs and having a slightly odd problem: the text is displaying above the frame that should hold it, like this:
The message is misaligned with the frame. Please align it better.
[_________________________________________________]
I'm generally using code looking like
Toast bread = Toast.makeText(getContext(), R.string.message, Toast.LENGTH_LONG);
bread.show();
from a dialog. I've heard bad context can sometimes cause inflation problems but getOwnerActivity()
is returning null, so that's out. In any case, I would have thought getContext() would supply the context passed in at construction time, which is the activity anyway.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你可以试试这个:
you can try this:
尝试更改这些值,直到获得准确的位置。
但使用 Gravity.CENTER 和其他常量是首选方式。
try playing around by changing those values till you get exact location.
But using
Gravity.CENTER
and other constants is the prefererrd way..如果您从 Activity 内部创建 Toast,则应使用:
this
或MyActivityName.this
作为上下文参数。If you create the toast from inside an activity you should use:
this
orMyActivityName.this
as the context parameter.使用。
尝试在清单文件中
Try using,
in your manifest file.