1,概念
Toast是用来显示信息的一种机制,没有焦点,显示时间有限。
Toast默认显示时间有2个:Toast.LENGTH_SHORT
和Toast.LENGTH_LONG
2,常见方法
toast.setDuration(duration) 设置显示多长时间
toast.setGravity(gravity, xOffset, yOffset) 设置Toast显示在屏幕上的位置
toast.setText(s) 设置Toast文本信息
toast.setView(view) 设置Toast显示的视图
toast.getDuration() 得到Toast显示的时间
toast.getView() 得到Toast的视图对象
3,自定义 Toast
平时调用:Toast(“this is mainActivity”);
函数:
private Toast toast = null;
private void Toast(String s){
if (toast != null) {
toast.cancel();
}
toast = Toast.makeText(this, s, Toast.LENGTH_SHORT);
toast.show();
}