My Toast have 3 lines, I want line 2 and 3 show center of this toast and set duration to 10 seconds.
How can do it?
Like this picture:
My Toast have 3 lines, I want line 2 and 3 show center of this toast and set duration to 10 seconds.
How can do it?
Like this picture:
\n inside the string works!!!
Toast.makeText(this, "line1\nLine2", Toast.LENGTH_SHORT).show();
You can customize Toast class. Here is example:
Context context=getApplicationContext();
LayoutInflater inflater=getLayoutInflater();
View customToastroot =inflater.inflate(R.layout.YOUR_TOAST_LAYOUT, null);
Toast customtoast=new Toast(context);
customtoast.setView(customToastroot);
customtoast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL,0, 0);
customtoast.setDuration(Toast.LENGTH_LONG);
customtoast.show();
Toast.makeText(this,"YOUR MESSAGE",
+"\n"+
"Your other message",
Toast.Lenght_long).show();
Each time you add a line with
+"\n"+
© 2022 - 2024 — McMap. All rights reserved.