To change the output position of Toast on Android

Asked 1 years ago, Updated 1 years ago, 96 views

When you put Toast on the screen, it's usually printed a little above the screen. I want to put Toast in the center of the screen where I want it, what should I do?

android toast

2022-09-21 18:19

1 Answers

If you look at http://developer.android.com/intl/ko/guide/topics/ui/notifiers/toasts.html,

Toast's default output position is slightly windowed below the screen, which can be replaced by the setGravity(int,int,int) method. Each parameter is sequentially the Gravity constant, the offset of x and the offset of y.

For example, if you want to have toast appear on the left at the top, toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0); You can do it in this way. If you want to print a little more to the right, you can increase the value in the second parameter, and if you want to print a little more to the bottom, you can increase the value in the third parameter.


2022-09-21 18:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.