Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plus Icon in Floating Action Button not rendered correctly in Android pre-Lollipop

I tried to setup a fab by using the support design library.

Code in XML:

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/fab"
    android:src="@drawable/ic_add_white_18dp"
    app:borderWidth="2dp"
    app:fabSize="normal"
    android:onClick="submit"
    app:rippleColor="@color/colorPrimaryDark">

</android.support.design.widget.FloatingActionButton>

On Nexus 6(lollipop), the plus icon is rendering correctly.

enter image description here

But on nexus 4(pre lollipop), plus icon size is crossing the circle.

enter image description here

I have downloaded and used the plus(ic_add_white_18dp) from Material icons

Icon Sizes used:

mdpi - 18dp
hdpi - 27dp
xdpi - 36dp
xxdpi - 54dp

enter image description here

What should be the correct size to use for plus icon.

like image 650
karsas Avatar asked Jun 28 '15 02:06

karsas


People also ask

How do I add icons to the floating action button?

Add the floating action button to your layout The size of the FAB, using the app:fabSize attribute or the setSize() method. The ripple color of the FAB, using the app:rippleColor attribute or the setRippleColor() method. The FAB icon, using the android:src attribute or the setImageDrawable() method.

How do I change the shape of the floating action button on Android?

To change the shape of the Floating action button: You can use the shape property of FloatingActionButton() widget class. Implement BeveledRectangleBorder( ) on this property. The output will be a square floating action button, increase the border-radius value to make a circular type shape.

How do I change the background on my floating action button?

To change background color of Floating Action Button in Kotlin Android, set the backgroundTint attribute (in layout file) or backgroundTintList property (in Kotlin file) of FAB with the required color.


1 Answers

Update

This has been fixed as of v22.2.1.


As it was stated on FloatingActionButton, square button below API level 17

Which referenced this bug: https://code.google.com/p/android/issues/detail?id=175067

Your FAB should have app:borderWidth="0dp"

like image 65
Logain Avatar answered Sep 29 '22 10:09

Logain