Search code examples
javaandroidandroid-toast

Method Toast.setView is deprecated


While I'm doing custom toast on my app, I noticed that setView is deprecated.

Code Screenshot

Does anyone have a solution for this?

toast.setView(customView);

Solution

  • Since setView is deprecated:

    This method was deprecated in API level 30. Custom toast views are deprecated. Apps can create a standard text toast with the makeText(android.content.Context, java.lang.CharSequence, int) method, or use a Snackbar when in the foreground. Starting from Android Build.VERSION_CODES#R, apps targeting API level Build.VERSION_CODES#R or higher that are in the background will not have custom toast views displayed.

    This makes sense Toasts can be displayed on Top of other Apps, some Apps can trick users by creating custom Toasts on Top of other Apps for their advantage even if their App is on the Background. But if your App is in the Foreground your custom Toast will still be shown in all Android Versions.