1、默认toast
Toast.makeText(ToastActivity.this,"hello",Toast.LENGTH_SHORT).show();
显示在底部的一个Toast
2、居中Toast
Toast toastCenter = Toast.makeText(getApplicationContext(),"居中对齐",Toast.LENGTH_SHORT);
toastCenter.setGravity(Gravity.CENTER,0,0);
toastCenter.show();
Toast显示在中间
3、自定义Toast
Toast toastCustom = new Toast(getApplicationContext());
LayoutInflater inflater = LayoutInflater.from(ToastActivity.this);
View view = inflater.inflate(R.layout.layout_toast,null);
ImageView imageView = view.findViewById(R.id.iv_toast);
TextView textView = view.findViewById(R.id.tv_toast);
imageView.setImageResource(R.mipmap.dianzan_select);
textView.setText("自定义toast");
toastCustom.setView(view);
toastCustom.show();