How to add Fab In your app

http://apk-dl.com/detail/image/xcom.melnykov.fab.sample-w150.png.pagespeed.ic.cRgFj0yvd6.png

Today i am going to share a guide on How to add fab button in your application. I already saw that many developers able to do this by editing Pngs in Photoshop or gimps etc. but that take time and much experience too so here i am going to help you in xml for creating fab Drawable.

So let Start.

  1. Decompile that application in which you want to add fab Button.
  2. Now we need to create a fab button drawable
  3. just create new xml name it fab_ic_add_btn.xml
  4. then put this code in it.
Code:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<layer-list>
<!-- Shadow -->
<item android:top="1dp" android:right="1dp">
<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>
</layer-list>
</item>

<!-- Blue button pressed -->
<item>
<shape android:shape="oval">
<solid android:color="#90CAF9"/>
</shape>
</item>
</layer-list>
</item>

<item android:state_enabled="true">

<layer-list>
<!-- Shadow -->
<item android:top="2dp" android:right="1dp">
<layer-list>
<item>
<shape android:shape="oval">
<solid android:color="#08000000"/>
<padding
android:bottom="4px"
android:left="4px"
android:right="4px"
android:top="4px"
/>
</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>
</layer-list>
</item>

<!-- Blue button -->
<item>
<shape android:shape="oval">
<solid android:color="#03A9F4"/>
</shape>
</item>
</layer-list>

</item>

</selector>
  1. Now You will have to download the icons which will be displayed on fab. You can download Plus Icons FAB from this link. Fab_icon_res.zip
  2. Copy these icons into your drawable files.
  3. Now we want to place this Fab button in our layout.
  4. Place the FAB in a FrameLayout and add your layouts above the FAB view. For best results, keep the FAB height and width at 72dp and in the bottom right of the FrameLayout.
  5. Code:
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!--

    Your layouts here. Do not put anything below the FAB layout

    -->

    <com.Droidbuster.materialfab.fab_btn
    android:id="@+id/fabbutton"
    android:layout_width="72dp"
    android:layout_height="72dp"
    android:layout_gravity="bottom|right"
    android:layout_marginBottom="16dp"
    android:background="@drawable/fab_ic_add_btn"
    android:src="@drawable/fab_ic_add"
    android:layout_marginRight="16dp" />

    </FrameLayout>
  6. Now i will demonstrate how to add target in our fab button. so that our smali editing part . haha ! dont worry its simple. its just like adding shortcut of any activity .
  7. so now download this zip. then extract this Fab_smali.zip. Copy all smali to your \smali\com folder
  8. Now go to com\Droidbuster\materialfab folder Now open fab_btn$1.smali with Notepad++
  9. Search for <!-- android:targetPackage --> Now change this your desired target package name.dont know what is this? targetPackage Name? I will explain in another post .haha!
  10. and Now Search for <!-- android:targetClass --> Change this code to your desired target Class Name.
  11. For example here is my my Targetpackage Name and targetClass name
Code:
     
android:targetPackage="com.android.mms"
android:targetClass="com.android.mms.ui.Conversati onList
  1. Now every thing done. compile your apk now push to your system.so now you can see your working fab button in Frame layout  
 CREDITS : Droidbuster@xda
Thanks for reading my news about How to add Fab In your app at my blog Bros Droid if you want too share this article, please put the resource, and if you think this article is very usefully dont forget to bookmark this site with CTRL + D on your keyboard to web browser.

New and Hot Article's :