galaxy - Android Toast moves around on screen -
my android app displays several toast messages. installed on galaxy s6, running android 5.1.1 , noticed messages displayed around center of screen, move proper position (near bottom, if no gravity specified), 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 set compile-sdk , target sdk latest api. did not fix issue
- i have removed .setgravity() calls. no change.
- i have noticed toast messages behave @ first execution after installation (be in usb debug mode or via download playstore), issue reoccurs @ (all) subsequent runs.
- i have discovered toast messages disappear if touch screen (anywhere). thought toast displays cannot influenced user interaction.
anyone else having issue, know how fix or know workaround?
please note have accepted nick's answer, proposing snackbar workaround.
your question asked fix or workaround. simplest workaround (in opinion) best option, because moves using more modern components: switch snackbar.
simple snackbar:
//on fragment can use getview(), otherwise give root view of //layout snackbar can use find context snackbar.make(getview(), "the toast text", snackbar.length_short).show();
it's in support design library compatibility.
this snackbar:
and of support / design libraries can 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'
Comments
Post a Comment