Toast主要用来提示用户,以实现友好的用户体验,这里给出两个Toast的例子:
1、使用图片
2、使用文字对话框
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(); |
01 | Toast toast = Toast.makeText( this , "lalalal" , Toast.LENGTH_LONG); |
02 | View textView = toast.getView(); |
03 | LinearLayout lay = new LinearLayout( this ); |
04 | lay.setOrientation(LinearLayout.HORIZONTAL); |
05 | ImageView view = new ImageView( this ); |
06 | view.setImageResource(R.drawable.icon); |
07 | lay.addView(view); |
08 | lay.addView(textView); |
09 | toast.setView(lay); |
10 | toast.show(); |