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:
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.
setGravity(Gravity. CENTER, 0, 0); toast.
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) ...
\n inside the string works!!!
Toast.makeText(this, "line1\nLine2", Toast.LENGTH_SHORT).show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With