Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – Positioning a toast to top

Posted on November 11, 2022 By

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()

custom toast by inflating

<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

READ  [FIXED] java - MediaStore.Audio.Media.EXTERNAL_CONTENT_URI is deprecated for api 29+?
Powered by Inline Related Posts
Android Tags:android, native, toast

Post navigation

Previous Post: [FIXED] android – Build not succed in flutter
Next Post: [FIXED] kotlin – Opening the application from the results google.com, always directs to the home page of WebView Android

Related Posts

[FIXED] android – How can I solve this problem while creating recyclerview? Android
[FIXED] How can Activity and its Views lifecycles overlap in android Android
[FIXED] android – LiveData from room and MutableLiveData to display error message Android
[FIXED] android – problem get products with retrofit (Woocommerce site) Android
[FIXED] android – Can I delete meta-data in AndroidManifest Android
[FIXED] android – Horizontal recyclerview with snaphelper, how to center first and last element? Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What color are dead flea eggs?
  • What is Indiana vine?
  • What’s the downside of a Chromebook?
  • Is phosphide the same as phosphorus?
  • Why do you need an S bend?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme