1

I'm trying to set up a basic BottomActionBar with an attached FloatingActionButton. Currently, everything seems to work, aside from the background of the bar. If I use android:background="some_background_color", the bar is filled in with the desired color.

The problem is that I want my FAB to be cradled, and this approach seems to be incompatible with fabCradleMargin and fabCradleRoundedCornerRadius, as the background bar is unaffected by modifying these values.

All tutorials indicate that app:backgroundTint="some_background_color" is the way to go, but my action bar remains unaffected by this. I've set my API to >= 21, so as far as I know, there are no issues there.

My XML file:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent">

        <com.google.android.material.bottomappbar.BottomAppBar
            android:id="@+id/bottom_app_bar"
            style="@style/Widget.MaterialComponents.BottomAppBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:backgroundTint="@color/colorPrimary"
            app:fabAlignmentMode="center"
            app:fabAttached="true"
            app:fabCradleMargin="10dp"
            app:fabCradleRoundedCornerRadius="10dp" />

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_add_white_24dp"
            app:layout_anchor="@+id/bottom_app_bar"
            app:layout_anchorGravity="center_horizontal"
            app:fabSize="normal"/>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

The backgroundTint has no effect on the bar; it remains completely white.

Sorry if this is an elementary question; I'm quite new to Android and have spent quite a while searching for a solution to no avail.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
hylian
  • 11
  • 2

1 Answers1

0

I tested your code it shows an error for BottomAppBar so I findout this code app:fabAttached="true" is Undefined...

remove it and it will work perfectly. Goodluck.