public static Toast custom(@NonNull Context context, CharSequence text, @Nullable Drawable icon,
@ColorInt int backgroundColor, int duration, @DrawableRes int resid,
@Nullable Typeface tp, float cornerRadius,
@ColorInt int textColor, float textSize) {
Toast toast = new Toast(context);
View layout = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.toast_layout, null);
LinearLayout ll = (LinearLayout) layout.findViewById(R.id.base_layout);
ll.setBackgroundResource(resid);
GradientDrawable gd = (GradientDrawable) ll.getBackground().getCurrent();
gd.setColor(backgroundColor);
gd.setCornerRadius(cornerRadius);
TextView tv_message = (TextView) layout.findViewById(R.id.toast_text);
tv_message.setTextSize(textSize);
tv_message.setTypeface(tp == null ? DEFAULT_TYPEFACE : tp);
tv_message.setTextColor(textColor);
ImageView iv_toast_image = (ImageView) layout.findViewById(R.id.toast_image);
if (icon != null) {
iv_toast_image.setImageDrawable(icon);
}
tv_message.setText(text);
toast.setView(layout);
toast.setDuration(duration);
return toast;
}
ButterToast.java 文件源码
java
阅读 34
收藏 0
点赞 0
评论 0
项目:ButterToast
作者:
评论列表
文章目录