Toast.makeText (...). Show () sometimes shifts

I use Toast.makeText to display the results from dialogs and with a slightly strange problem: the text is displayed above the frame that should hold it, for example:

The message is biased with the frame. Please align it better. [ _________________________________________________ ]

I usually use code similar to

Toast bread = Toast.makeText(getContext(), R.string.message, Toast.LENGTH_LONG);
bread.show();

from the dialogue. I heard that a bad context can sometimes cause inflation problems, but it getOwnerActivity()returns null, so that is the way out. In any case, I would have thought that getContext () would provide the context passed at build time, which is activity anyway.

Any suggestions?

+5
source share
4 answers

you can try the following:

Toast bread = Toast.makeText(getApplicationContext(), R.string.message, Toast.LENGTH_LONG);
bread.show();
+20
source
bread.setGravity(5,5,5);

try playing by changing these values ​​until you get the exact location.

But using Gravity.CENTERother constants is the preferred way.

+3
source

, : this MyActivityName.this .

+1

<supports-screens
   android:largeScreens="true"
   android:normalScreens="true"
   android:smallScreens="true"
   android:anyDensity="true" /> 

.

+1

All Articles