在 Toast 中居中文本 [英] Center text in a Toast

查看:34
本文介绍了在 Toast 中居中文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有办法将 Toast 中的所有文本显示为居中.例如,我有一个 Toast,其中有 2 行文本.纯粹出于审美原因,我希望文本居中对齐而不是左对齐.我已经浏览了文档,但找不到任何关于它的信息.有没有一种简单的方法可以做到这一点,但我错过了?

I was wondering if there was a way to display all text in a Toast to be centered. For instance, I have a Toast that has 2 lines of text in it. For purely aesthetic reasons, I would like the text to center-aligned instead of left-aligned. I've looked through the documentation and can't find anything about it. Is there a simple way to do this that I have missed?

推荐答案

使用 Toast 的 setView(view) 函数提供带有 Gravity.CENTER 的 View.

Use the Toast's setView(view) function to supply a View with Gravity.CENTER.

这篇关于在 Toast 中居中文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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