According to https://developer.android.com/about/versions/11/behavior-changes-11#toasts, Toasts should still work as normal for Android11 (only setView() was deprecated).
Note that text toasts are still allowed; these are toasts created using Toast.makeText() that don't call setView().
However, I cannot get Toast to show for emulators running SDK30 with
compileSdkVersion 30
buildToolsVersion "30.0.3"
and with targetSdkVersion 30
The code used was just a simple
Toast.makeText(getApplicationContext(), "HELLO WORLD", Toast.LENGTH_SHORT).show();
The toast is displayed when I change the targetSdk to 29 (or with devices <SDK30).
Do I need to add any <queries> tags in manifest file for Toasts ? https://developer.android.com/about/versions/11/privacy/package-visibility
I've also tried the following without luck.
makeText(context, "Hello world, I am a toast.", Toast. LENGTH_SHORT). show(); The duration for which a toast is displayed on screen is unfortunately defined by a flag: you can either show it for a SHORT duration, which is 2 seconds or a LONG duration which is 3,5 seconds.
If a simple text message isn't enough, you can create a customized layout for your toast notification. To create a custom layout, define a View layout, in XML or in your application code, and pass the root View object to the setView (View) method. Notice that the ID of the LinearLayout element is "toast_layout".
Positioning your Toast A standard toast notification appears near the bottom of the screen, centered horizontally. You can change this position with the setGravity(int, int, int) method. This accepts three parameters: a Gravity constant, an x-position offset, and a y-position offset.
Updating of Android Emulator
to 30.4.5
version fixed bug for me. P.S. I also updated Android SDK Platform-Tools
to 31.0.0
version (may be this helped too).
Menu Tools
-> SDK Manager
-> SDK Tools
, set checkbox of Android Emulator
to V
-mode, press button Apply
, press button OK
, confirm.
P.S. Also after updating of those the Android Studio and emulators were closed and project was cleaned before new compilation.
If you get this bug while using the last version of Android Emulator there is another solution. You can try the cold boot of emulator. Menu Tools
-> AVD Manager
. Find your emulator name, click button ▼ on the right side of it, select Cold boot now
button.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With