I have used toasts in my android projects to display text. Can I use toasts to display an image popup message. If so can someone give me some useful code segment. Thank You!
-
2You could create a custom dialog and use animation to make it appear in a faded motion just like a toast – Rahul Gupta Dec 09 '13 at 05:37
-
1http://learnandroideasily.blogspot.in/2013/05/android-custom-toast.html Check that one out. – Dhaval Dec 09 '13 at 05:37
-
yep. I can use a custom dialog. But what i need is the message should disappear in a short time as a toast. can I do that with a custom dialog. – Samantha Withanage Dec 09 '13 at 05:39
-
2refer this post http://stackoverflow.com/questions/7571917/adding-image-to-toast – Shijil Dec 09 '13 at 05:41
3 Answers
You can see my sample code via this link: https://github.com/Hesamedin/CustomToast
The most important class is this class which drived from Toast class and modified it.
Then use it in normal way as Toast usage like this:
btnCustomToast = (Button) findViewById(R.id.btnCustomToast);
btnCustomToast.setTypeface(pacificoFont);
btnCustomToast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MyToast.makeText(getApplicationContext(), "This is custom toast message.", Toast.LENGTH_LONG).show();
}
});

- 52,260
- 74
- 224
- 365
As I commented in this post you can use my SuperToasts library if you do not feel like creating your own Toast View. You can easily display an image with the following code:
SuperToast superToast = new SuperToast(getActivity());
superToast.setDuration(SuperToast.DURATION_LONG);
superToast.setText("Hello world!");
superToast.setIconResource(R.drawable.image, SuperToast.IconPosition.LEFT);
superToast.show();
The library also comes with a bunch of icons already made and has a bunch of configurable options such as animations, backgrounds, text colors etc. Alternatively you can use SuperActivityToasts if you need to use a Toast within an Activity which will give you access to clickable buttons, progress bars, dismiss listeners etc.
-
oops ! I got some problem. When I use a SuperToast inside a fragment the app got stop. what's the reason for this and how can I fix it. – Samantha Withanage Dec 12 '13 at 08:57
-
You have to use an Activity Context for the SuperActivityToast. What's the stacktrace say? – John P. Dec 12 '13 at 17:32
-
@JohnP. I can't seem to find a `setView` method like normal Toasts support? How can I set a custom layout file as the view? – edwoollard Jan 25 '17 at 10:44
Its possible to do with toast
Code:Add this in your code part
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.like_popup, (ViewGroup) activity.findViewById(R.id.like_popup_layout));
ImageView imageView = (ImageView) layout.findViewById(R.id.like_popup_iv);
imageView.setBackgroundResource(R.drawable.white_delete_icon);
Toast toast = new Toast(activity.getApplicationContext());
toast.setGravity(Gravity.BOTTOM, 0, 200);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
Design:like_popup.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cred_menu_like_popup_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/customshapetransparent"
android:paddingTop="35dp"
android:paddingBottom="25dp"
android:paddingLeft="35dp"
android:paddingRight="35dp"
>
<ImageView
android:id="@+id/like_popup_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
Design: customshapetransparent.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#60000000" />
<corners android:radius="8dp" />
</shape>
Hope this will give you what you want to achive

- 1,538
- 16
- 24