1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Show snack bar above FAB in androidx

Discussion in 'Programming/Internet' started by newakkoff, Sep 12, 2018.

  1. newakkoff

    newakkoff Guest

    trying create app using androidx. my layout

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    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=".ui.photo.PhotoFragment">


    <ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

    <androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerPhoto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_anchorGravity="top|center"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:itemCount="48"
    tools:layoutManager="GridLayoutManager"
    tools:listitem="@layout/recycler_photo_item"
    tools:spanCount="3" />

    <androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/photoCoordinator"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    >

    <com.google.android.material.bottomappbar.BottomAppBar
    android:id="@+id/mainBottomAppBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    app:fabAlignmentMode="center"
    android:backgroundTint="@color/colorPrimary"
    app:fabCradleMargin="@dimen/cradle_margin"
    app:fabCradleRoundedCornerRadius="@dimen/corner_radius"
    app:hideOnScroll="true"
    app:navigationIcon="@drawable/ic_menu_24px" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/photoFab"
    style="@style/Widget.MaterialComponents.FloatingActionButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_camera_alt_24px"
    app:layout_anchor="@id/mainBottomAppBar" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>


    and its looks like that [​IMG] when i showing snackbar its looks like this [​IMG] google says that snackbar should showing above bottom app bar and fab but i cant when trying to show snack bar with bottom margin

    val snackbarView = snackbar.view
    val params = snackbarView.layoutParams as CoordinatorLayout.LayoutParams

    params.setMargins(
    params.leftMargin + marginSide,
    params.topMargin,
    params.rightMargin + marginSide,
    params.bottomMargin + marginBottom
    )

    snackbarView.layoutParams = params


    fab ups to! how can i show snackbar above fab and bottom app bar? sorry for my engllish!

    Login To add answer/comment
     

Share This Page