1

I am displaying a toast in my screen, but the position of the toast appears to vary from device to device, i want the toast to be displayed at one particular position for all the screen sizes.Please help me out with this.

Thanks!

srikanth
  • 301
  • 3
  • 14

3 Answers3

4

First you need to get the screen dimensions.

Use them to calculate the toast's position, and place it in the appropriate position.

Community
  • 1
  • 1
zmbq
  • 38,013
  • 14
  • 101
  • 171
  • Screen dimensions vary from device to device, so the position is also varying from device to device. – srikanth Sep 16 '13 at 07:56
  • Which is why I suggested you *get the screen dimensions* first. Check the first link out. – zmbq Sep 16 '13 at 08:01
1

For any one if facing this same problem would suggest you to try this out

IMP is that you are not in the activity class

  WindowManager wm = (WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE);
  Display display = wm.getDefaultDisplay();
  Point size = new Point();
  display.getSize(size);
    int width=size.x;
    int height=size.y;

where appcontext is ur own appcontext.


but if you are in the activity class you can use this

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
srikanth
  • 301
  • 3
  • 14
0

You may create a custom Toast message with a custom xml layout. Refer this example on Android Developers.