On Mon, 31 Jan 2022 13:44:10 +0100, Jakub wrote:
> Is possible to create custom Toast at Android 30+
I have a good heart so I usually try to help answer questions, but in this
case, I don't even know what a "toast" is (although I vaguely remember
something about toast notifications on the Windows newsgroup long ago).
Running the obligatory search
<
https://duckduckgo.com/?q=what+is+android+custom+toast+example>
First hit is:
*Android | What is Toast and How to use it with Examples*
<
https://www.geeksforgeeks.org/android-what-is-toast-and-how-to-use-it-with-examples/>
"A toast is a feedback message that displays for a few seconds"
"A custom toast uses images instead of a simple message."
That article goes on to show how to _create_ a custom toast, but now we get
to the detail that the OP is asking, as we can assume the OP perhaps likely
knows something we don't about what's different about SDK 30 and above.
Modifying the search for the OP to find what changed in SDK 30 or so
<
https://duckduckgo.com/?q=sdk+30+android+custom+toast+changes>
First hit is:
*Android 11: Custom toasts from the background are blocked*
<
https://developer.android.com/about/versions/11/behavior-changes-11#toasts>
"For security reasons and to maintain a good user experience, the system
blocks toasts that contain custom views if those toasts are sent from
the background by an app that targets Android 11 or higher.
Note that text toasts are still allowed; these are toasts created using
Toast.makeText() that don't call setView().
If your app tries to post a toast containing a custom view from the
background anyway, the system doesn't show the message to the user.
Instead, the system logs the following message in logcat:"
Now that I have a rudimentary idea of what a "toast" even is, and then what
a "custom toast" is, and then what _changed_ (apparently in Android 12), I
provide the OP the suggestion that is made here for how to solve the issue.
<
https://developer.android.com/about/versions/11/reference/compat-framework-changes>
"If your app targets Android 12 (API level 31) or higher, its toast is
limited to two lines of text and shows the application icon next to the
text. Be aware that the line length of this text varies by screen size,
so it's good to make the text as short as possible.
Alternatives to using toasts
If your app is in the foreground, consider using a snackbar instead of
using a toast. Snackbars include user-actionable options, which can
provide a better app experience.
If your app is in the background, and you want users to take some action,
use a notification instead.:"
In summary, my _first_ response, given I'm a kind hearted person who enjoys
helping others, is to suggest the OP consider using a "snackbar", although I
do profess utter ignorance myself of what a "snackbar" even is.
Before I delve into what a snackbar is, I'll let the OP respond as I don't
want to lead the OP astray given I'm completely ignorant of this topic.
--
Ignorance can be cured; it's stupidity that knows no cure.