2012-02-07 19 views

回答

4

這裏:

Toast toast = Toast.makeText(this, "Message", Toast.LENGTH_SHORT); 
toast.setGravity(Gravity.CENTER, 0, 0); 
toast.show(); 
+2

比你@dmytrodanylyk但竟被我喜歡將中間的文字設置在中間,而不是全部的敬酒。 – 2012-02-07 12:24:25

6

吐司是建立在一個TextView和它的默認重力左對​​齊。所以,你需要創建自己的TextView這樣的,例如:

<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的吐司是這樣的:

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

Source

+0

謝謝拉烏爾,我會試試這個。 – 2012-02-07 12:23:33

+0

+1顯示來源。 – Ghost 2012-02-07 12:45:28