Toast

From google material design documentation.

Android also provides a toast, primarily used for system messaging. Toasts are similar to snackbars but do not contain actions and cannot be swiped off screen.

How to add?

Create Toast instance with make() method. Then call show() method.

Toast.makeText(context, "No network connection.", duration).show();  

Duration

To specify how long Toast will be visible on screen use duration parameter of makeText() method or setDuration method.

// you can use only those 2 predefined constants
duration = Toast.LENGTH_SHORT; // 2000 millis  
duration = Toast.LENGTH_LONG; // 3500 millis

toast.setDuration(duration);  

Cancel

To hide Toast manually at any time use cancel() method.

Toast toast= Toast.make(view, text, duration).show();  
toast.cancel(); //hide toast  

Close the view if it's showing, or don't show it if it isn't showing yet. You do not normally have to call this. Normally view will disappear on its own after the appropriate duration.

Positioning

To change position of Toast use setGravity() method.

int gravity = Gravity.CENTER; // the position of toast  
int xOffset = 0; // horizontal offset from current gravity  
int yOffset = 0; // vertical offset from current gravity 

Toast toast= Toast.make(view, text, duration);  
toast.setGravity(gravity, xOffset, yOffset);  

How to style?

With code

// create instance
Toast toast = Toast.makeText(context, text, duration);

// set message color
TextView textView= (TextView) toast.getView().findViewById(android.R.id.message);  
textView.setTextColor(Color.YELLOW);

// set background color
toast.getView().setBackgroundColor(getResources().getColor(R.color.indigo));  

With custom view

I. Declare your custom view inside of any layout.xml file.

<?xml version="1.0" encoding="utf-8"?>  
<TextView  
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/txtMessage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableStart="@drawable/ic_report_problem"
        android:drawablePadding="8dp"
        android:paddingTop="8dp"
        android:paddingBottom="8dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:gravity="center"
        android:textColor="@android:color/white"
        android:textSize="16dp"
        android:text="No connection."
        android:background="@color/indigo"/>

II. Set your custom view to Toast via setView() method.

// create instance
Toast toast = new Toast(getApplicationContext());

// inflate custom view
View view = getLayoutInflater().inflate(R.layout.toast_view, null);

// set custom view
toast.setView(view);

// set duration
toast.setDuration(Toast.LENGTH_LONG);

// set position
int margin = getResources().getDimensionPixelSize(R.dimen.toast_vertical_margin);  
toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_VERTICAL, 0, margin);

// show toast
toast.show();