問題描述
Адлюстраванне тоста з зададзеным зрушэннем (Displaying toast at a given offset)
I am having trouble displaying a toast at a given offset in a Google Maps application for Android.
Here is my code:
static public void DisplayCustomToast (Context displayContext, string stringText, int offsetX, int offsetY)
{
Toast toast = new Toast(displayContext);
toast.SetText(stringText);
toast.SetGravity (GravityFlags.Top, offsetX, offsetY);
toast.Show();
}
When the emulator starts up, and I try and execute this code from the onCreate method via:
DisplayCustomToast(this, "test", ‑30, 50);
The application stops working totally and the cell phone main background is shown.
Can I please have some help to display a custom toast at a given offset for Android.
Thanks
‑‑‑‑‑
參考解法
方法 1:
try to do this
Toast toast = Toast.makeText(MainActivity.this,"Test",Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP|Gravity.LEFT, ‑30, 50);
toast.show();
方法 2:
try this..
toast.SetGravity (GravityFlags.Top, 0, 0);
(by Garry、Talha、Nirav Tukadiya)