Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Circular button with shadow like 5.0 FAB

I want a button in circular shape with shadow. Shadow must be like FAB. Currently I'm using a png to implement the button.

enter image description here

But when I use this image I can't give correct pressed state changes. Is there any way to impleament this by using xml

like image 411
shine_joseph Avatar asked Jan 09 '15 13:01

shine_joseph


2 Answers

Create circle.xml under drawable folder

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="oval">
    <solid android:color="#03ae3c"/>
</shape> 

set this as background for layout or view. then assign elevation attribute to your view. that will give you visual appearance of its shadow.

<LinearLayout
            android:layout_width="250dp"
            android:layout_height="250dp"
            android:background="@drawable/circle"
            android:elevation="14dp"
            android:orientation="vertical"/>
like image 90
sivaBE35 Avatar answered Oct 05 '22 10:10

sivaBE35


you can try it

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- Drop Shadow Stack -->
    <item>
        <shape android:shape="oval">
            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#00CCCCCC" />

            <corners android:radius="3dp" />
        </shape>
    </item>
    <item>
        <shape android:shape="oval">
            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#10CCCCCC" />

            <corners android:radius="3dp" />
        </shape>
    </item>
    <item>
        <shape android:shape="oval">
            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#20CCCCCC" />

            <corners android:radius="3dp" />
        </shape>
    </item>
    <item>
        <shape android:shape="oval">
            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#30CCCCCC" />

            <corners android:radius="3dp" />
        </shape>
    </item>
    <item>
        <shape android:shape="oval">
            <padding
                android:bottom="1dp"
                android:left="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#50CCCCCC" />

            <corners android:radius="3dp" />
        </shape>
    </item>

    <!-- Background -->
    <item>
        <shape android:shape="oval">
            <solid android:color="@android:color/white" />

            <corners android:radius="3dp" />
        </shape>
    </item>

</layer-list>

 <Button
        android:id="@+id/btn"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_centerInParent="true"
        android:background="@drawable/shadow_circle"
        android:text="0"
        android:textColor="#fff" />

enter image description here

like image 32
Hoa.Tran Avatar answered Oct 05 '22 10:10

Hoa.Tran