Skip to content

Commit

Permalink
Custom Toast Without icon is added
Browse files Browse the repository at this point in the history
  • Loading branch information
sad-adnan committed Mar 12, 2021
1 parent 6654687 commit 7b33da0
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 7b33da0

Please sign in to comment.