2

I need to create a custom animated toast message. Now i need to know if that is possible. I've created a toast with a custom view but I cannot figure out how can I add custom animation to the toast.

Here is the code I have so far.

 private void showToast() { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup) findViewById(R.id.custom_toast_layout_id)); // set a message TextView text = (TextView) layout.findViewById(R.id.toast_text); text.setText("Button is clicked!"); // Toast... Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); } }); } 
3
  • 1
    isnt it easy to just create a custom view that will look like a toast and apply to it whatever you want? Commented Aug 3, 2013 at 15:34
  • Look here: Custom animation for Toast enter/exit? you cannot add custom animation to Toast only custom View that you have already done. Commented Aug 3, 2013 at 15:34
  • According to @Sajmon answer and this developer.android.com/guide/topics/graphics/view-animation.html simply add the animation to the view as you would do with any other view, I am not sure if it will work but give it a try! Commented Aug 3, 2013 at 15:38

2 Answers 2

2

It is not possible to do this with the stock Android Toast class. Stock style toasts (ones added to the WindowManager and not to a ViewGroup) are limited to four system animations and will not accept animations from your project. If you would like to use different system animations with stock type Android Toasts check out how I do it in my SuperToasts library. It may not be worth it to write such a class for one instance so I would recommend either using my library if you find it useful or writing a custom view class that resembles a toast. You can see how I do that in this class of the library.

Sign up to request clarification or add additional context in comments.

Comments

0

Toasts are displayed using a system that can't be changed so answer is no you cant change the toast animation. however you can make your own view that resembles a toast and animate it however you want.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.