android自定义toast

public static void getMyToast(Context context , int imageResource , String content , int time){
Toast toast = new Toast(context);

toast.setDuration(time);//设置时间

toast.setGravity(Gravity.CENTER, 0,25 ); // 设置出现的位置
//自定义布局
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.setGravity(Gravity.CENTER_VERTICAL);

ImageView imageView = new ImageView(context);
imageView.setImageResource(R.drawable.ic_launcher);

TextView textView = new TextView(context);
textView.setText(content);

linearLayout.addView(imageView);
linearLayout.addView(textView);


toast.setView(linearLayout);
toast.show();
}

原文地址:https://www.cnblogs.com/li-fei/p/4278237.html