Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Simple Android App (2014) Testing and Debugging Toast Notifications

Brendan Milton
Brendan Milton
9,050 Points

Loving this android development course! is it possible to make the Toast appear on a different part of the screen?

Loving this android development course! is it possible to make the Toast appear on a different part of the screen? e.g. higher up, so it doesn't appear so messy.

2 Answers

Hello,

I have not tried this yet, but it appears to be possible according to this post on stackoverflow. To do this you'd want to create the toast and store it as a variable, while not showing it. Then you'd want to use the following code:

toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 0);

where Gravity.TOP|Gravity.CENTER_HORIZONTAL are Gravity contents ORed together and the following two numbers are the x and y offsets from the defined Gravity position that you want the toast placed.

Brendan Milton
Brendan Milton
9,050 Points

Thank you so much, i'll give it a go!