How to create a circle button in the lower right corner of Android 5+?

Are there standard tools or existing libraries for creating a circle button, for example, in the Gmail application? enter image description here

+6
source share
3 answers

In the android support design support library, one of the widgets presented is a floating action button, which is usually added in the lower right corner (but it should not be used only there)

The floating action button is a circular button that indicates the main action on your interface. The Design FloatingActionButton libraries give you the only consistent implementation, colored by default using colorAccent from your theme.

To get the Android design support library in the build.gradle file, add the following:

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 the Android Design Support Library are here.

There are also many other libraries that provide FAB, for example

+2
source

1.The first important thing is using Android Studio

2. Add, depending on your build.gradle:

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

3. Creating 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 namespace

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

to the layout file.

  1. You can also set the button type (regular or mini) using the fab_type xml attribute (this is normal by default):

fab:fab_type="mini"

or

fab.setType(FloatingActionButton.TYPE_MINI);

+2
source

Yes, with the new Design Support Library , the implementation of the default floating action button is implemented.

To access the new FAB class, you will need to add this dependency to the gradle assembly file.

 compile 'com.android.support:design:22.2.0' 
+1
source

Source: https://habr.com/ru/post/989482/


All Articles