How make action float menu with android.support.design
I maked layout with these buttons, and then include to fragment layout. But maybe i make something wrong... And you have some ideas to help me.
fab.xml
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fab_menu"
android:layout_margin="16dp"
android:src="#drawable/ic_add" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fab_done"
android:layout_margin="16dp"
android:src="#drawable/ic_done" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fab_cancel"
android:layout_margin="16dp"
android:src="#drawable/ic_cancel" />
And how make animation, when I click at the button to show another buttons?
There are lots of cool libraries that were designed to make it easy to create different FABs.
library by futuresimple
library by Clans
and library by makovkastar
Related
i have problem with FloatingActionButton in RelatieLayout. I use DP for margin top and left. When i change device button is not on it's place. You can see on screens. First one is from editor, second from device.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="3dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="3dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewFloor5"
android:layout_width="match_parent"
android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="430dp"
android:layout_marginLeft="300dp"
app:backgroundTint="#color/primaryColor"
android:src="#drawable/ic_action_calendar"
app:fabSize="normal"
android:id="#+id/floorActionButton"/>
</RelativeLayout>
[
I also tried android:gravity="center|bottom" but nothing happens.
I also tried android:gravity="center|bottom" but nothing happens.
Since you are using RelativeLayout - gravity won't work. Instead use android:layout_alignParentBottom along with the margins
<RelativeLayout
....
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="16dp"
app:backgroundTint="#color/primaryColor"
android:src="#drawable/ic_action_calendar"
app:fabSize="normal"
android:id="#+id/floorActionButton"/>
</RelativeLayout>
Try this...Don't use margin to set FloatingActionButton position always use gravity.
Follow this tutorial from androidhive.
https://www.androidhive.info/2015/12/android-material-design-floating-action-button/
I have set layoutgravity but use appropriately according to the parentlayout properties for gravity.
If you follow the tutorial above it will be easy for in my case i placed the fab in a </android.support.design.widget.CoordinatorLayout> and included the layout inside it like in the tutorial.
Just follow it it will be easy just don't use margin to set its position it will break in different screens like your above error .
<android.support.design.widget.FloatingActionButton
android:id="#+id/floorActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:backgroundTint="#color/primaryColor"
android:src="#drawable/ic_action_calendar"
app:fabSize="normal"/>
I added circular floating action menu to my app but I can't find anywhere option to add label to elements. Can some has any idea how to add text?
I used this tutorial:
http://androidlift.info/2015/10/12/create-floating-action-button-fab-android/
Circular floating menu can be created easily in ConstraintLayout. layout_constraintCircle, layout_constraintCircleAngle, layout_constraintCircleRadius this property of ConstraintLayout will help you to create circular positioning of views.
Check this official documentation.
layout_constraintCircle is for the id of the center view
layout_constraintCircleAngle is for the angle of the circular positioning view
layout_constraintCircleRadius is for the radius of the circle.
This is a sample xml code for Arc menu:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".CircularPositioningActivity">
<android.support.design.widget.FloatingActionButton
android:id="#+id/fabMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="#drawable/ic_menu_white_24dp" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fabAttachFile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
app:layout_constraintCircle="#id/fabMenu"
app:layout_constraintCircleAngle="270"
app:layout_constraintCircleRadius="100dp"
app:srcCompat="#drawable/ic_attach_file_white_24dp"
/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fabAudio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
app:layout_constraintCircle="#id/fabMenu"
app:layout_constraintCircleAngle="315"
app:layout_constraintCircleRadius="100dp"
app:srcCompat="#drawable/ic_audiotrack_white_24dp" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fabCamera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
app:layout_constraintCircle="#id/fabMenu"
app:layout_constraintCircleAngle="0"
app:layout_constraintCircleRadius="100dp"
app:srcCompat="#drawable/ic_camera_alt_white_24dp" />
<android.support.constraint.Group
android:id="#+id/group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="fabAttachFile,fabCamera,fabAudio"
/>
</android.support.constraint.ConstraintLayout>
This is how it look like
can't find anywhere option to add label to elements
You can replace each circular positioning views with viewgroup or different layout for adding multiple view. This is the easiest way to do with out any library.
I am doing some operation on floating action button . I have a list view and showing google ad at bottom of my screen, The floating action button is showing at same place (bottom|end). so action button is hiding the ad.
I want shift the Floating action button little above the ad linear layout.
Please have a look the image:
My code is look like:
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|end"
android:src="#drawable/fav"
android:adjustViewBounds="false" />
adLayoutId is ad layout id
Please help.
Thanks in advance.
You should use RelativeLayout, and as we know, later children in a RelativeLayout tend to float over earlier children in a RelativeLayout.
So, to have a FAB float over of any layout, make sure that the FAB is defined after all views (at the end of the XML layout).
If you use android:layout_margin="#dimen/fab_margin" the best way to manipulate FAB is set dependencies between views, for example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/adLayoutId"/>
<LinearLayout
android:id="#+id/adLayoutId"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#android:color/black"/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/adLayoutId"
android:layout_alignParentRight="true"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/fav"/>
</RelativeLayout>
Floating action button always will be above the ad linear layout, and independent from ad layout size.
Hope it helps.
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="100dp"
android:layout_marginRight="30dp"
/>
These two lines inside the fab button helped me solved this problem:
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Here's the entire code I used for the button alone:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab_newStudent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
android:contentDescription="#string/todo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="#drawable/ic_baseline_add_24" />
THESE TWO LINES ARE IMPORTANT.
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
Add a bottom Margin of 55dp which is the size of Admob Banners
This line in either the floating button or enclosing layout.
android:layout_marginBottom="55dp
When I use background and src in android.support.design.FloatingActionbutton it is not set correctly. Instead it is displayed as
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/pink"
android:src="#drawable/ic_action_barcode_2"
android:layout_gravity="bottom|right"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp" />
but when I use ImageView it appears correctly as
<ImageView
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/pink"
android:src="#drawable/ic_action_barcode_2"
android:layout_gravity="bottom|right"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp" />
why is FloatingActionButton is not displayed correctly? What should I change in my code?
Floating action button's background does not need to be changed, you just apply a tint and then add your icon as usual
<android.support.design.widget.FloatingActionButton
...
app:backgroundTint="#color/ic_action_barcode_2"
android:src="#drawable/ic_add" />
This provides you with a round button still but in the colour you desire.
In this case the app namespace is used for the support library features:
xmlns:app="http://schemas.android.com/apk/res-auto"
i faced the similar problem. I tried to set src or background of FloatingActionButton, but couldn't fill the button by src. following code solved problem for me.
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
.
.
.
android:background="#drawable/round_icon"
android:backgroundTintMode="src_over">
I wanted to implement a floating action button in android studio and I followed all the steps: Adding dependencies, adding the xmlns to the layout and making the floatingbuttion in the xml as follows:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.clans.fab.FloatingActionButton
android:id="#+id/fab"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="bottom|right"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
fab:fab_colorNormal="#color/primary"
fab:fab_colorPressed="#color/accent"
fab:fab_colorRipple="#color/primary_dark" />
</FrameLayout>
but in the preview I got a gray, empty square. What am I doing wrong?
I am not sure, but I think you have to include a src
Please reply if it helped you!
<android.support.design.widget.FloatingActionButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/fab"
android:src="#drawable/abc_ic_search_api_mtrl_alpha"
android:layout_alignBottom="#+id/recyclerview"
android:layout_alignRight="#+id/recyclerview"
android:layout_alignEnd="#+id/recyclerview" />
Please add the code "app:borderWidth="0dp" as property.