48

Starting with Android 12, Google show a toast message with an app icon.

My application have launcher icon. Android 12 splash screen show app icon correctly.

Show toast by code

Toast.makeText(this, "Show simple toast", Toast.LENGTH_LONG).show()

compileSdkVersion/targetSdkVersion 31

android emulator Google play Intel x86 Atom_64 System Image API Level 31, Revision 8.

How can i change this default toast icon?

enter image description here

Denis
  • 2,622
  • 3
  • 22
  • 24
  • 2
    Did you find the answer? I can't find any documentation for this and your question is the first result on Google. – Mickaël Oct 27 '21 at 10:17
  • 1
    I think you will have better luck with `Snackbar` – cutiko Oct 27 '21 at 12:24
  • 2
    Is the toast icon referenced in `android:icon="@drawable/ic_launcher"` ? The ic_launcher files are png's in mipmap-XXXX. Which dpi folder they are using? Or they use the mipmap-anydpi-v26/ic_launcher.xml file? – Saftpresse99 May 19 '22 at 13:44

5 Answers5

41

For me a simple restart of the device did the trick.

I had not restarted my test phone after the update to Android 12 at all. I experienced the same odd bug that a generic app icon was shown in Toasts issued by my app. I tried changing the Manifest as Mickaël‘s answer suggested. No luck. I ended up with the exact same Manifest the app had before I started debugging … and then I restarted the device. My app now displays the correct icon in Toasts reliably. What happened? Unsure. I suspect that a restart may trigger an icon cache refresh that crawls all installed apps in search for new/updated app icons.

Y20K
  • 493
  • 3
  • 6
12

Seems like this issue was reported to Google, and assigned to a Google engineer: https://issuetracker.google.com/issues/202863198

speller
  • 1,641
  • 2
  • 20
  • 27
  • Should be resolved in an upcoming Android update, as posted on that thread 1/5/22: "The issue has been fixed and it will be available in a future build." – mike47 Jan 20 '22 at 01:40
2

From me the restart of the phone work as well. The toasts now show the proper App Icon, configured in my apps. If it does not work for you please review this statement and check if everything is properly set for you app icon. I hope that this will help :) https://developer.android.com/studio/write/image-asset-studio

PS: There is one more place from which you can build your app icons https://romannurik.github.io/AndroidAssetStudio/index.html

Fireball
  • 41
  • 6
1

After running a few tests, I found that setting <application android:icon="@drawable/ic_stat_name" ... with a drawable generated with Image Asset > Notification Icons is overriding the default toast icon.

However, this doesn't work with a drawable generated as Image Asset > Launcher Icons. So at this point, I guess something is missing in Android Studio's generation tool.

Mickaël
  • 310
  • 3
  • 8
1
public void CustomToast(Context context,String text,int ico,int duration)
{
    //define new Toast Object
    Toast toast = new Toast(context.getApplicationContext());
    //create TextView Object to set icon for it
    TextView tv_toast=new TextView(context);
    //get text from parameter for toast
    tv_toast.setText(text);
    //set background color and radius for my toast
    GradientDrawable gd = new GradientDrawable();
    gd.setColor(Color.GRAY);
    gd.setCornerRadius(20);
    gd.setStroke(1, 0xFF000000);
    //applying setting to tv
    tv_toast.setBackground(gd);
    //set icon
    tv_toast.setCompoundDrawablesWithIntrinsicBounds(ico, 0, 0, 0);
    //set duration
    toast.setDuration(duration);
    //ending- set my custom style for toast object
    toast.setView(tv_toast);
    // then show it
    toast.show();
}
San Nasser
  • 13
  • 1
  • 3