Android的设置文本对齐到土司中间 [英] Android Set the text align to the middle of the toast

查看:102
本文介绍了Android的设置文本对齐到土司中间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个敬酒的消息是pretty的长。我想设置文本的中间,而不是开始对齐到左边。

I have a toast message which is pretty long. I would like to set the text in the middle and not to start align to the left.

这可能吗?

推荐答案

吐司是建立在一个TextView和它的默认重力左对​​齐。所以,你需要创建自己的TextView这样的,例如:

Toast is built on a TextView and the default gravity of it is left aligned. So, you need to create your own TextView like this for instance :

<TextView       
android:layout_width="fill_parent"      
android:layout_height="fill_parent"      
android:gravity="center_vertical|center_horizontal"     
android:text="all the text you want" /> 

和您指定的TextView的吐司是这样的:

And you assign the TextView to the Toast like this :

Toast t = new Toast(yourContext); 
t.setView(yourNewTextView); 

来源

这篇关于Android的设置文本对齐到土司中间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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