How do I make my button look more like the Floating Action Button?
My button so far looks close but as yet, doesn't look the same. What other changes would you suggest?
An image of what the Floating Action Button looks like is below, as is an image of my button so far and my code so far
An image of the actual Floating Action Button is below:
An image of my actual Button so far is below:
My API is v19
Code:
Code for actual button
<Button
android:layout_width="wrap_content"
android:layout_height="60dp"
android:text="+"
android:textSize="60sp"
android:background="@drawable/addbutton"
android:elevation="3dp"
android:layout_marginTop="215dp"
android:layout_marginLeft="310dp"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:textColor="#ffff" />
Addbutton.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape android:shape="oval">
<solid android:color="#08000000"/>
<padding
android:bottom="3px"
android:left="3px"
android:right="3px"
android:top="3px"
/>
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#09000000"/>
<padding
android:bottom="2px"
android:left="2px"
android:right="2px"
android:top="2px"
/>
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#10000000"/>
<padding
android:bottom="2px"
android:left="2px"
android:right="2px"
android:top="2px"
/>
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#11000000"/>
<padding
android:bottom="1px"
android:left="1px"
android:right="1px"
android:top="1px"
/>
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#12000000"/>
<padding
android:bottom="1px"
android:left="1px"
android:right="1px"
android:top="1px"
/>
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#13000000"/>
<padding
android:bottom="1px"
android:left="1px"
android:right="1px"
android:top="1px"
/>
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#14000000"/>
<padding
android:bottom="1px"
android:left="1px"
android:right="1px"
android:top="1px"
/>
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#15000000"/>
<padding
android:bottom="1px"
android:left="1px"
android:right="1px"
android:top="1px"
/>
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#16000000"/>
<padding
android:bottom="1px"
android:left="1px"
android:right="1px"
android:top="1px"
/>
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#17000000"/>
<padding
android:bottom="1px"
android:left="1px"
android:right="1px"
android:top="1px"
/>
</shape>
</item>
</layer-list>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#FF4186"/>
</shape>
</item>
</layer-list>
I have been using the following library for my app (I'm not the author). It seems to work very well, looks just like a FAB and even can be easily attached to a listview to autohide when you scroll down. The library is easy to add through gradle too. The image/animation on the github page makes the button look low quality but it isn't in real life and looks exactly like the google versions.
https://github.com/makovkastar/FloatingActionButton
I build this kind of button in my app using this code
Code in Fragment.xml
Code for drawable (round_button_shape)
Code for round shape Drawable
Additionaly i would recommend to use this code within a selector to provide feedback if the user interact with the button
Result:
Button in a layout:
Explanation:
margin
provides some space for the elevationgravity
centers the background drawable and the textstateListAnimator
set to null so it doesn't mess with elevation (it can be animated via this)res/drawables-v21/add_button_selector.xml
res/drawables/add_button_selector.xml:
res/drawables/add_button.xml:
res/drawables/add_button_selected.xml:
Explanation:
Notes