Search code examples
androidtoastandroid-toast

Image icon within Toast maketext message


I am beginning learning some android mobile development and have created a notepad app through some tutorials and am now wanting to customise it a little.

I currently have a Toast maketext message that displays when a user saves a new note. The code is as follows:

if(Utilities.saveNote(this, new Note(mNoteCreationTime, title, content))) 
Toast.makeText(this, "Swag Note has been saved", Toast.LENGTH_SHORT).show();

What I am wanting to do is add a small icon at both ends of this toast message.

Is there a relatively simple way of achieving this?


Solution

  • Toasts cannot have icons. You can create a custom Toast with ImageViews in it (example). However, there might be an unicode symbol that suits your purpose: in that case, you can just paste it.

    Edit:

    To make the linked example work, you'd just have to add a View for the image with id "toast_image", which will be invoked this way:

    ImageView image = (ImageView) layout.findViewById(R.id.toast_image);
    

    Show Toast as you do it now:

    Toast.makeText(this, "Swag Note has been saved", Toast.LENGTH_SHORT).show();
    

    Show MyToast from linked example:

    MyToast.show(this, "Swag Note has been saved", false);