Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Change the alignment of Toast by Programmatically? [duplicate]

Tags:

android

toast

Possible Duplicate:
how to change position of Toast in android?

How to change the Alignment for Toast? Basically, toast it'll displays information bottom of the device. How can we change that? Anyone help me to find out this? Thanks in Advance.

like image 684
Praveenkumar Avatar asked Nov 30 '22 16:11

Praveenkumar


1 Answers

It would be a nice idea to create a Custom Toast like this,

        TextView textview = new TextView(context);
        textview.setText(text);
        textview.setBackgroundColor(Color.GRAY);
        textview.setTextColor(Color.BLUE);
        textview.setPadding(10,10,10,10);
        Toast toast = new Toast(context);
        toast.setView(textview);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.setGravity(Gravity.BOTTOM, 0, 0);
        toast.show();

By this you can place the Toast to anywhere you want using Gravity

like image 153
Lalit Poptani Avatar answered Dec 10 '22 12:12

Lalit Poptani