1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
public void showToast(String sayWhat, int imageid,int length,Context
context){
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,(ViewGroup) findViewById(R.id.toast_layout_root));
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(imageid);
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText(sayWhat);
Toast toast = new Toast(context);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
if (length == 0){
toast.setDuration(Toast.LENGTH_LONG);
}else {
toast.setDuration(Toast.LENGTH_SHORT);
}
toast.setView(layout);
toast.show();
} |