1

No, this is not a duplicate question. seems to be duplicate link.That is the question that solved the issue of FAB in square which is below <API 16. But here in API 16.,It is working.Only the above,that mean API 21,it is in SQUARE.

I have implemented a Floating Action Button.Initially it was circle in shape.Later I changed its background color using,

app:backgroundTint="@android:color/holo_green_dark" even I tried

app:borderWidth="0dp" to get in Circle in shape.But these way didn't help me.

In API 16 it is working nice. Only an issue in API 21.

xml:

  <android.support.design.widget.FloatingActionButton
            android:id="@+id/cartfab1"
            style="@style/Layout_ww"
            android:layout_above="@+id/txt_categoryName"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_gravity="right"
            android:layout_marginEnd="40dp"
            android:layout_marginRight="40dp"
            android:src="@drawable/ic_shopping_cart"
            app:backgroundTint="@color/colorPrimary"
            app:borderWidth="0dp" />
Community
  • 1
  • 1
Parama Sudha
  • 2,583
  • 3
  • 29
  • 48

2 Answers2

1

In your layout

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:shapeAppearanceOverlay="@style/fab_rounded"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    app:srcCompat="@android:drawable/ic_dialog_email" />

In your values/styles.xml

<style name="fab_3_rounded">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSize">50%</item>
    <item name="cornerSizeTopLeft">20dp</item>
    <item name="cornerSizeTopRight">20dp</item>
    <item name="cornerSizeBottomLeft">20dp</item>
    <item name="cornerSizeBottomRight">20dp</item>
</style>

This will give you a rounded, set cornerSizeTopLeft, cornerSizeTopRight, cornerSizeBottomLeft and cornerSizeBottomRight and adjust them to the size you want. If you want square change it to 0dp for each section

Aldan
  • 674
  • 9
  • 23
-2

Fixed the bug.

In my xml layout I used these code inside of Floating Action Bar for changing this as a desired color.

app:backgroundTint="@android:color/holo_green_dark" 

here, I imported

xmlns:app="http://schemas.android.com/tools"

After changing this to,

xmlns:app="http://schemas.android.com/apk/res-auto".

It is working nice even in API 21.

Parama Sudha
  • 2,583
  • 3
  • 29
  • 48