0

once i heard if you can't do something 15 minutes ask help... I trying myself already 2 days.

Now I need your help.

I want make fab center cut in AppBar bottom in android studio

This don't work for me link 1 and this link 2

enter screen

screen 2

Code in screen 2

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ActionMenu">
    <com.google.android.material.appbar.AppBarLayout     
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">
    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/primaryDarkColor"
        app:popupTheme="@style/AppTheme.PopupOverlay" />
    </com.google.android.material.appbar.AppBarLayout>
    <include
        android:id="@+id/include"
        layout="@layout/content_action_menu" />
    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppBar2"
        style="@style/Widget.MaterialComponents.BottomAppBar.Colored"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/primaryDarkColor"
        app:fabAttached="true"
        android:gravity="bottom"
        app:elevation="8dp"
        app:fabAlignmentMode="center"
        app:layout_anchor="@+id/include"
        app:layout_anchorGravity="bottom|center" />
    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        app:elevation="8dp"
        app:layout_anchor="@+id/bottomAppBar2"
        app:layout_anchorGravity="center|fill_vertical"
        app:srcCompat="@android:drawable/ic_menu_add" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

How make fab center cut in AppBar bottom?

Thanks for attention

kirya355
  • 33
  • 6
  • Could you please be more specific when asking your questions. Try to boil the question down to one problem at a time then provide/add code so that others may reproduce your issue. – mccurcio Feb 27 '20 at 20:08

1 Answers1

1

I believe the code you're looking for is

app:fabCradleMargin="(x DP here)"

as an attribute of the floating action button.

Here's a layout from a project of mine that's doing exactly what you're looking for:

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:orientation="horizontal"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="1">

    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppBar"
        style="@style/Widget.MaterialComponents.BottomAppBar.Colored"
        android:layout_width="match_parent"
        android:layout_height="46dp"
        android:layout_gravity="bottom"
        app:backgroundTint="@color/colorPrimary"
        app:layout_anchor="@+id/bottomAppBar"
        app:layout_anchorGravity="bottom"
        app:menu="@menu/app_bar_menu"
        app:fabAnimationMode="slide"
        app:fabCradleRoundedCornerRadius="8dp"
        app:navigationIcon="@drawable/ic_settings"

        />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:clickable="true"
        app:backgroundTint="@color/colorAccent"
        app:layout_anchor="@id/bottomAppBar"
        app:maxImageSize="40dp"
        app:srcCompat="@drawable/ic_scan"
        app:tint="@color/colorWhite" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Cameron C
  • 11
  • 2