From 7b33da02a46845b57a36bfce8089bb4643967f2b Mon Sep 17 00:00:00 2001 From: "MD. Sad Adnan" Date: Fri, 12 Mar 2021 15:11:15 +0600 Subject: [PATCH] Custom Toast Without icon is added --- .../sadadnan/customtoastlib/CustomToast.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/CustomToastLibrary/src/main/java/com/sadadnan/customtoastlib/CustomToast.java b/CustomToastLibrary/src/main/java/com/sadadnan/customtoastlib/CustomToast.java index ceca680..01dc258 100644 --- a/CustomToastLibrary/src/main/java/com/sadadnan/customtoastlib/CustomToast.java +++ b/CustomToastLibrary/src/main/java/com/sadadnan/customtoastlib/CustomToast.java @@ -96,4 +96,30 @@ public static void showToastWithCustomDrawableAndBG(Context mContext, boolean is toast.setView(custom_view); toast.show(); } + + public static void showToastWithoutIcon(Context mContext, boolean isLong, String message, int colorRes) { + Toast toast = new Toast(mContext); + if (isLong) { + toast.setDuration(Toast.LENGTH_LONG); + } else { + toast.setDuration(Toast.LENGTH_SHORT); + } + + //inflate view + View custom_view = ((AppCompatActivity) mContext).getLayoutInflater().inflate(R.layout.toast_icon_text, null); + ((TextView) custom_view.findViewById(R.id.message)).setText(message); + + + ((ImageView) custom_view.findViewById(R.id.icon)).setVisibility(View.GONE); + + try { + ((CardView) custom_view.findViewById(R.id.parent_view)).setCardBackgroundColor(((AppCompatActivity) mContext).getResources().getColor(colorRes)); + } catch (Resources.NotFoundException e) { + e.printStackTrace(); + ((CardView) custom_view.findViewById(R.id.parent_view)).setCardBackgroundColor(((AppCompatActivity) mContext).getResources().getColor(R.color.blue500)); + } + + toast.setView(custom_view); + toast.show(); + } }