Answer by Amardeep for How to change position of Toast in Android?
//A custom toast class where you can show custom or default toast as desired) public class ToastMessage { private Context context; private static ToastMessage instance; /** * @param context */ private...
View ArticleAnswer by Mithun Adhikari for How to change position of Toast in Android?
The method to change the color, position and background color of toast is: Toast toast=Toast.makeText(getApplicationContext(),"This is advanced toast",Toast.LENGTH_LONG);...
View ArticleAnswer by nzala for How to change position of Toast in Android?
Toast toast = Toast.makeText(test.this,"bbb", Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show();
View ArticleAnswer by JDJ for How to change position of Toast in Android?
You can customize the location of your Toast by using: setGravity(int gravity, int xOffset, int yOffset) docs This allows you to be very specific about where you want the location of your Toast to be....
View ArticleAnswer by user3652986 for How to change position of Toast in Android?
Toast mytoast= Toast.makeText(getApplicationContext(), "Toast Message", 1); mytoast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0); // for center horizontal //mytoast.setGravity(Gravity.CENTER_VERTICAL);...
View ArticleAnswer by Rymnel for How to change position of Toast in Android?
If you get an error indicating that you must call makeText, the following code will fix it: Toast toast= Toast.makeText(getApplicationContext(), "Your string here", Toast.LENGTH_SHORT);...
View ArticleAnswer by Pentium10 for How to change position of Toast in Android?
From the documentation, Positioning your Toast A standard toast notification appears near the bottom of the screen, centered horizontally. You can change this position with the setGravity(int, int,...
View ArticleHow to change position of Toast in Android?
When I use Toast to display some popup text on the screen, it displays the text a little bit above the bottom of the screen, which is the default position. Now I want to display it in the middle of...
View ArticleAnswer by Jorn Rigter for How to change position of Toast in Android?
For people like me, looking for an answer to set the gravity on Toasts on Android R and above, see this article.
View ArticleAnswer by abdulwasey20 for How to change position of Toast in Android?
From the documentation:Warning: Starting from Android Build.VERSION_CODES#R, for apps targeting API level Build.VERSION_CODES#R or higher, this method (setGravity) is a no-op when called on text...
View ArticleAnswer by Javaid Iqbal for How to change position of Toast in Android?
Toast toast = Toast.makeText(this, "Custom toast creation", Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM | Gravity.RIGHT,0,0); toast.show();
View ArticleAnswer by Shailendra for How to change position of Toast in Android?
Toast toast = Toast.makeText(test.this,"bbb", Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show();//this is the best solution to counter any error
View ArticleAnswer by Ali Akram for How to change position of Toast in Android?
SOLUTIONfun Context.showToastOnTOP(message: String) = Toast.makeText(this, message, Toast.LENGTH_SHORT) .apply { setGravity(Gravity.TOP, 0, 0); show() }fun Context.showToastOnBOTTOM(message: String) =...
View Article