您可以通过以下代码更改吐司位置.
Toast toast= Toast.makeText(getApplicationContext(),
"Your string here", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
Run Code Online (Sandbox Code Playgroud)
从文档中,
定位你的吐司
标准吐司通知出现在屏幕底部附近,水平居中.您可以使用该
setGravity(int, int, int)方法更改此位置 .这接受三个参数:Gravity常量,x-position偏移和y-position偏移.例如,如果您确定吐司应该出现在左上角,您可以像这样设置重力:
Run Code Online (Sandbox Code Playgroud)toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);如果要将位置微移到右侧,请增加第二个参数的值.要轻推它,请增加最后一个参数的值.
| 归档时间: |
|
| 查看次数: |
5664 次 |
| 最近记录: |