Reputation: 433
My android app displays several Toast messages. I recently installed it on a Galaxy S6, running Android 5.1.1 and noticed that the messages are displayed initially around the center of the screen, then they move to proper position (near bottom, if no Gravity is specified), then back to the initial position before fading away.
Context context = getApplicationContext();
String newMsg = getString(R.string.wild_card_msg);
Toast mToast = Toast.makeText(context, newMsg, Toast.LENGTH_LONG);
mToast.setGravity(Gravity.CENTER, 0, 0);
mToast.show();
Update:
Anyone else having this issue, know how to fix it or know a workaround?
Please note that I have accepted Nick's answer, proposing snackBar as a workaround.
Upvotes: 15
Views: 1377
Reputation: 21733
Your question asked for a fix or workaround. The simplest workaround is (in my opinion) also the best option, because it moves you to using the more modern components: Switch to a snackbar.
Simple Snackbar:
//on a fragment you can simply use getView(), otherwise give it the root view of your
//layout so that the snackbar can use it to find context
Snackbar.make(getView(), "The toast text", Snackbar.LENGTH_SHORT).show();
It's in the support design library for compatibility.
This is a snackbar:
And some of the support / design libraries that can be included in gradle are
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
Upvotes: 7
Reputation: 16614
It is because of the customized version of Android that vendors deploy with their products, It is true for Activity animations too, You can achieve the desired behavior on all devices by extending the Toast class and providing your own animation and style or using an open source library for showing toast messages, for activities setting a custom animation for activities creates a constant animation on all devices.
Upvotes: 3
Reputation: 2648
try this simple Toast
Toast.makeText(getApplicationContext(),"Your message", Toast.LENGTH_SHORT).show();
Upvotes: -2