(1)默认:
Toast.makeText(this,"!!!!!!",Toast.LENGTH_SHORT).show();
(2)改变位置:
Toast toast = Toast.makeText(ToastDemoActivity.this,"我是吐司!!!",Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER,0,0);
toast.show();
(3)图片加文字:
Toast t = new Toast(ToastDemoActivity.this);
//设置文本内容
TextView textTitle = new TextView(ToastDemoActivity.this);
textTitle.setText("猫");
TextView textView = new TextView(ToastDemoActivity.this);
textView.setText("可爱的喵喵");
//设置图片
ImageView imageView = new ImageView(ToastDemoActivity.this);
imageView.setImageResource(R.mipmap.ic_launcher);
//组合文本加图片,可以设置线性布局
LinearLayout layout=new LinearLayout(ToastDemoActivity.this);
layout.setOrientation(LinearLayout.VERTICAL);//设置LinearLayout垂直
layout.setGravity(Gravity.CENTER);//设置LinearLayout里面内容中心分布
layout.addView(textTitle);//先添加title
layout.addView(imageView);//再添加image
layout.addView(textView);//再添加view
//只需要把layout设置进入Toast
t.setView(layout);
t.setGravity(Gravity.CENTER,0,0);
t.setDuration(Toast.LENGTH_SHORT);
t.show();