Solution 1 :
Toast.makeText(MainActivity.this,"Sample Toast",Toast.LENGTH_LONG)
.setGravity(Gravity.CENTER_VERTICAL,0, 0)
.show();
Problem :
The inflating a custom toast it is not positioned on the top like the system toast using Toast.makeToast(). Is it possible to position the custom inflated toast to the same place as the system toast?
system toast using Toast.makeText()
<LinearLayout xmlns_android="http://schemas.android.com/apk/res/android"
xmlns_app="http://schemas.android.com/apk/res-auto"
xmlns_tools="http://schemas.android.com/tools"
android_id="@+id/toastLayout"
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_orientation="vertical"
android_background="#00000000"
tools_ignore="UseCompoundDrawables">
<androidx.cardview.widget.CardView
android_id="@+id/containerView"
android_layout_gravity="center"
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_orientation="vertical"
app_cardCornerRadius="40dp"
app_cardElevation="16dp"
android_background="@android:color/darker_gray"
app_cardUseCompatPadding="true"
tools_ignore="UnusedAttribute">
<TextView
android_id="@+id/toastTitle"
android_layout_width="wrap_content"
android_layout_height="wrap_content"/>
</androidx.cardview.widget.CardView>
</LinearLayout>
I think the problem is using cardElevation the higher the value the lower it appear on the scree. Any idea to overcome this problem?
Comments
Comment posted by Muhamed El-Banna
\ if my answer works .. please mark it as accepted answer .. thanks in advance