两种实现Toast 的例子(图片&文字)
Toast主要用来提示用户,以实现友好的用户体验,这里给出两个Toast的例子:
1、使用图片
- Toast toast = new Toast(this);
- ImageView view = new ImageView(this);
- view.setImageResource(R.drawable.icon);
- toast.setView(view);
- toast.show();
2、使用文字对话框
- Toast toast = Toast.makeText(this, "lalalal", Toast.LENGTH_LONG);
- View textView = toast.getView();
- LinearLayout lay = new LinearLayout(this);
- lay.setOrientation(LinearLayout.HORIZONTAL);
- ImageView view = new ImageView(this);
- view.setImageResource(R.drawable.icon);
- lay.addView(view);
- lay.addView(textView);
- toast.setView(lay);
- toast.show();