Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set text new line in Toast at center android

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:

enter image description here

like image 816
Noisyman Avatar asked May 24 '16 18:05

Noisyman


People also ask

Can we change the position of toast message in Android?

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, int) method. This accepts three parameters: a Gravity constant, an x-position offset, and a y-position offset.

How do you set toast in the center?

setGravity(Gravity. CENTER, 0, 0); toast.

How do I customize a toast on Android?

Creating a Custom Toast View. To create a custom toast view, you need to create a custom layout file in XML and pass the root View object to the setView(View) method. First, retrieve the LayoutInflater with getLayoutInflater() (or getSystemService() ), and then inflate the layout from XML using inflate(int, ViewGroup) ...


1 Answers

\n inside the string works!!!

Toast.makeText(this, "line1\nLine2", Toast.LENGTH_SHORT).show();
like image 187
Shlomi Fresko Avatar answered Jan 04 '23 06:01

Shlomi Fresko