我厌倦了这段代码:
Toast toast = new Toast(this);
toast.setText("Please enter your User-Id");
toast.setGravity(Gravity.CENTER, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
但是吐司仍在底部显示,这是默认设置。即便如此,这也不起作用:
toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);
请帮忙。
此致
答案 0 :(得分:4)
您不应该使用Toast类的构造函数。
执行以下操作:
Toast toast = Toast.makeText(this, "Please enter your User-Id", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();