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:
- I have upgraded support libraries as well as set compile-sdk and target sdk to the latest API. That did not fix the issue
- I have removed all .setGravity() calls. No change.
- I have noticed that Toast messages behave properly at the first execution after installation (be it in USB debug mode or via download from PlayStore), but the issue reoccurs at (all) subsequent runs.
- I have also discovered that my Toast messages disappear immediately if I touch the screen (anywhere). I thought Toast displays cannot be influenced by user interaction.
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.
setGravity()
? – FaymToast.setGravity(Gravity.CENTER, 0, 0);
– Thekla