In Android I want to display a toast message at the bottom of the screen, I tried this:
Toast.makeText(test.this,\"bbb\", Toast.LENGTH_LONG).show();
In Xamarin.Android, this displays toast at center of screen:
Toast toast = Toast.MakeText(ApplicationContext, "bbb", ToastLength.Long);
toast.SetGravity(GravityFlags.Center, 0, 0);
toast.Show();
Toast toast = new Toast(context);
toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0);
toast.show();
Showing/ Setting text gravity at center (Horizontally) in koltin
fun Context.longToast(msg: String) {
Toast.makeText(this, msg, Toast.LENGTH_LONG)
.apply {
view.findViewById<TextView>(android.R.id.message)?.gravity = Gravity.CENTER
}
.show()
}
The following code can be used to display Toast message
Toast tt = Toast.makeText(MainActivity.this,"Your text displayed here", Toast.LENGTH_LONG);
tt.setGravity(Gravity.CENTER, 0, 0);
tt.show();
To display the Toast in center of the screen.
Toast toast = Toast.makeText(test.this,"bbb", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
The below code worked for me.
Toast.makeText(this, "Toast in center", Toast.LENGTH_SHORT).setGravity(Gravity.CENTER,0,0).show();