自定义Toast

来源:互联网 发布:seo是什么职位 编辑:程序博客网 时间:2024/06/05 19:39

实现很简单,直接上代码

public class MyToast {    //传过来的参数,MyToast.showMyToast(this, R.drawable.notification, "杀死了"+count+"个进程");public static void  showMyToast(Context context, int icon , String text){Toast toast = new Toast(context);View view = View.inflate(context, R.layout.mytoast, null);TextView tv_toast = (TextView) view.findViewById(R.id.tv_toast);ImageView iv_toast = (ImageView) view.findViewById(R.id.iv_toast);tv_toast.setText(text);iv_toast.setImageResource(icon);toast.setView(view);toast.setDuration(Toast.LENGTH_SHORT);toast.show();}}


0 0