两种实现Toast 的例子(图片&文字)

Toast主要用来提示用户,以实现友好的用户体验,这里给出两个Toast的例子

1、使用图片

  1. Toast toast = new Toast(this);
  2. ImageView view = new ImageView(this);
  3. view.setImageResource(R.drawable.icon);
  4. toast.setView(view);
  5. toast.show();

2、使用文字对话框

  1. Toast toast = Toast.makeText(this, "lalalal", Toast.LENGTH_LONG);
  2. View textView = toast.getView();
  3. LinearLayout lay = new LinearLayout(this);
  4. lay.setOrientation(LinearLayout.HORIZONTAL);
  5. ImageView view = new ImageView(this);
  6. view.setImageResource(R.drawable.icon);
  7. lay.addView(view);
  8. lay.addView(textView);
  9. toast.setView(lay);
  10. toast.show();

你可能感兴趣的:(toast)