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();
}

posted @   gin飞飞ing  阅读(123)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示