public class MyToast {
public static void myToast(Context context, String toast_text) {
if (null == context || toast_text == null){
return;
}
int strokeWidth = 6;
int roundRadius = 8;
int strokeColor = Color.parseColor("#a1afc9");
int fillColor = Color.parseColor("#e0000000");
GradientDrawable gd = new GradientDrawable();
gd.setColor(fillColor);
gd.setCornerRadius(roundRadius);
gd.setStroke(strokeWidth, strokeColor);
TextView txtViewToast = new TextView(context);
txtViewToast.setGravity(Gravity.CENTER);
txtViewToast.setTextColor(Color.parseColor("#ffffffff"));
txtViewToast.setTextSize(32);
txtViewToast.setMaxEms(12);
txtViewToast.setText(toast_text);
RelativeLayout mRelativeLayout = new RelativeLayout(context);
mRelativeLayout.setLayoutParams(new LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT));
mRelativeLayout.setPadding(25, 25, 25, 25);
mRelativeLayout.setBackground(gd);
mRelativeLayout.addView(txtViewToast);
Toast toast = new Toast(context);
toast.setView(mRelativeLayout);
toast.setDuration(Toast.LENGTH_SHORT);
toast.show();
}
}
public static void myToast(Context context, String toast_text) {
if (null == context || toast_text == null){
return;
}
int strokeWidth = 6;
int roundRadius = 8;
int strokeColor = Color.parseColor("#a1afc9");
int fillColor = Color.parseColor("#e0000000");
GradientDrawable gd = new GradientDrawable();
gd.setColor(fillColor);
gd.setCornerRadius(roundRadius);
gd.setStroke(strokeWidth, strokeColor);
TextView txtViewToast = new TextView(context);
txtViewToast.setGravity(Gravity.CENTER);
txtViewToast.setTextColor(Color.parseColor("#ffffffff"));
txtViewToast.setTextSize(32);
txtViewToast.setMaxEms(12);
txtViewToast.setText(toast_text);
RelativeLayout mRelativeLayout = new RelativeLayout(context);
mRelativeLayout.setLayoutParams(new LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT));
mRelativeLayout.setPadding(25, 25, 25, 25);
mRelativeLayout.setBackground(gd);
mRelativeLayout.addView(txtViewToast);
Toast toast = new Toast(context);
toast.setView(mRelativeLayout);
toast.setDuration(Toast.LENGTH_SHORT);
toast.show();
}
}