How to display Toast at center of screen

后端 未结 8 1833
北荒
北荒 2021-01-30 09:48

In Android I want to display a toast message at the bottom of the screen, I tried this:

Toast.makeText(test.this,\"bbb\", Toast.LENGTH_LONG).show();
8条回答
  •  一个人的身影
    2021-01-30 10:49

    Positioning your Toast

    A standard toast notification appears near the bottom of the screen, centered horizontally. You can change this position with the setGravity(int, int, int) method. This accepts three parameters: a Gravity constant, an x-position offset, and a y-position offset.

    For example, if you decide that the toast should appear in the top-left corner, you can set the gravity like this:

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

    If you want to nudge the position to the right, increase the value of the second parameter. To nudge it down, increase the value of the last parameter.

提交回复
热议问题