1

I was wondering is it possible to display Toast in other shapes other than the rectangle shape? I want to be able to display my Toast in this shape shown below if possible. I have looked but found nothing, any help will be appreciated.

Thanks in advance.

enter image description here

Madona wambua
  • 1,408
  • 1
  • 21
  • 37
  • 1
    How hard have you been looking? http://stackoverflow.com/questions/16909476/how-to-customize-toast-in-android – Dreo Aug 18 '15 at 22:47
  • 1
    possible duplicate of [Custom toast in android : a simple example](http://stackoverflow.com/questions/11288475/custom-toast-in-android-a-simple-example) – Buddy Aug 18 '15 at 22:50
  • [Tutorial](http://www.learn-android-easily.com/2013/05/customiozing-toast-in-android.html) – dieter_h Aug 18 '15 at 22:50

3 Answers3

0

Yes. It's possible. Check this guide under "costum toast"

Custom toast guide

Simone Pessotto
  • 1,561
  • 1
  • 15
  • 19
0

Yes it is possible:

custom_toast.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/toast_layout"
              android:orientation="horizontal"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content">
    <ImageView 
               android:src="@drawable/yourimage"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"

               />
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textColor="#FFF"
              />
</LinearLayout>

In your code:

LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
                               (ViewGroup) findViewById(R.id.toast_layout));

TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("This is a custom toast");

Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
Aakash
  • 5,181
  • 5
  • 20
  • 37
0

Yes, you can. Here is an example:

custom_toast.xml

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toast_layout_root"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="8dp"
    android:background="#DAAA">

    <ImageView
        android:src="@drawable/droid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="8dp" />

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#FFF" />

</LinearLayout>

Java Code:

LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup) findViewById(R.id.toast_layout_root));

TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("This is a custom toast");

Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();

More Info: http://developer.android.com/guide/topics/ui/notifiers/toasts.html#CustomToastView

Hussein El Feky
  • 6,627
  • 5
  • 44
  • 57