Android Positioning Toast
Positioning Toast:
”Positioning Toast” is a feature that can help the developer specify where on the screen a Toast message is to be placed.
In the simplest form, a Toast message is a message that slides in at the bottom of the screen by default.
However, as for the position of the Toast, they have the liberty of redesigning it depending on the needs.
Example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PositioningToastExample">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:gravity="center">
<Button
android:id="@+id/topToast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TOP"
android:textColor="@color/colorWhite"
android:background="@color/colorOrange"
android:layout_marginBottom="15dp"
/>
<Button
android:id="@+id/bottomToast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="BOTTOM"
android:textColor="@color/colorWhite"
android:background="@color/colorOrange"
android:layout_marginBottom="15dp"
/>
<Button
android:id="@+id/leftToast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="LEFT"
android:textColor="@color/colorWhite"
android:background="@color/colorOrange"
android:layout_marginBottom="15dp"
/>
<Button
android:id="@+id/rightToast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RIGHT"
android:textColor="@color/colorWhite"
android:background="@color/colorOrange"
android:layout_marginBottom="15dp"
/>
<Button
android:id="@+id/centerToast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CENTER"
android:textColor="@color/colorWhite"
android:background="@color/colorOrange"
android:layout_marginBottom="15dp"
/>
<Button
android:id="@+id/center_horizontalToast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CENTER HORIZONTAL"
android:textColor="@color/colorWhite"
android:background="@color/colorOrange"
android:layout_marginBottom="15dp"
/>
<Button
android:id="@+id/center_verticalToast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CENTER VERTICAL"
android:textColor="@color/colorWhite"
android:background="@color/colorOrange"
android:layout_marginBottom="15dp"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Output