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();

相关文章:

  • 2021-10-16
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 1970-01-01
猜你喜欢
  • 2021-12-15
  • 2022-12-23
  • 2021-12-13
  • 2022-02-02
  • 2022-02-10
  • 2021-09-12
相关资源
相似解决方案