Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a circle button in the right bottom corner on Android 5+?

Is there any standard tools or existing libraries to create a circle button like on Gmail App? enter image description here

like image 863
Semen Tykhonenko Avatar asked Jun 21 '15 18:06

Semen Tykhonenko


2 Answers

In the android support design support library one of the widgets provided is the Floating Action Button, which is usually added in the bottom right corner(but need not be used only there)

A floating action button is a round button denoting a primary action on your interface. The Design library’s FloatingActionButton gives you a single consistent implementation, by default colored using the colorAccent from your theme.

To get the android design support library in your build.gradle file, add this:

compile 'com.android.support:design:22.2.0'

In your layout file"

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

       <android.support.design.widget.FloatingActionButton
            android:id="@+id/myFAB"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"  
            app:layout_anchor="@id/appbar"
            app:layout_anchorGravity="bottom|right|end"
            android:src="@drawable/ic_discuss"
            android:layout_margin="10dp"
            android:clickable="true"/>
</RelativeLayout>

Details of android design support library here

Also there are many other libraries providing the FAB like

  • https://github.com/makovkastar/FloatingActionButton
  • https://github.com/futuresimple/android-floating-action-button
like image 65
Psypher Avatar answered Sep 25 '22 00:09

Psypher


1.First important thing use Android Studio

2.Add as a dependency to your build.gradle:

dependencies {
compile 'com.melnykov:floatingactionbutton:1.3.0'
}

3. Create a layout

<ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

<com.melnykov.fab.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_margin="16dp"
        android:src="@drawable/ic_action_content_new"
        fab:fab_colorNormal="@color/primary"
        fab:fab_colorPressed="@color/primary_pressed"
        fab:fab_colorRipple="@color/ripple" />

4.Add the namespace

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

to your layout file.

  1. You can also Set the button type (normal or mini) via the fab_type xml attribute (default is normal):

fab:fab_type="mini"

or

fab.setType(FloatingActionButton.TYPE_MINI);

like image 29
Abhishek Avatar answered Sep 25 '22 00:09

Abhishek