about how to display a picture in a toast, first customize a toast, customize a layout, this layout you want the toast to show what kind of layout you define, and then put a imageview in the custom layout, plug your own custom layout into the toast, Then call your own custom toast on the go.
This is what I do, although the more ugly can explain the problem.
is a custom toast code:
Package com.rytong.toast;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.Toast;
public class Mainactivity extends Activity {
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Button btn = (button) Findviewbyid (R.ID.BTN);
Btn.setonclicklistener (New Onclicklistener () {
public void OnClick (View v) {
TODO auto-generated Method Stub
Mytoast.mytosat (Mainactivity.this, R.drawable.icon, "show Pictures", Toast.length_long);
}
});
}
}
Package com.rytong.toast;
Import Android.content.Context;
Import Android.graphics.Color;
Import android.view.Gravity;
Import Android.widget.ImageView;
Import Android.widget.LinearLayout;
Import Android.widget.TextView;
Import Android.widget.Toast;
public class Mytoast {
public static void Mytosat (context context, int imageId, String content, int duration) {
New A toast pass in the context of the activity to be displayed
Toast toast = new toast (context);
The time displayed
Toast.setduration (duration);
Where to display
Toast.setgravity (gravity.bottom, 0, 300);
To lay out a toast again
LinearLayout toastlayout = new LinearLayout (context);
Toastlayout.setorientation (linearlayout.horizontal);
Toastlayout.setgravity (gravity.center_vertical);
ImageView ImageView = new ImageView (context);
Imageview.setimageresource (IMAGEID);
Add the ImageView to the Toastlayout layout
Toastlayout.addview (ImageView);
TextView TextView = new TextView (context);
Textview.settext (content);
Textview.setbackgroundcolor (Color.gray);
Add the TextView to the Toastlayout layout
Toastlayout.addview (TextView);
Toastlayout.setbackgroundcolor (Color.gray);
Add Toastlayout to the toast layout
Toast.setview (toastlayout);
Toast.show ();
}
}
Show pictures in Toast