I'm using the material components FloatingActionButton https://material.io/develop/android/components/floating-action-button/
In that, I can't able to add elevation for my fab I tried using the below code but it's not working
app:elevation="12dp"
app:borderWidth="0dp"
Here is my xml.
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/mfab"
style="#style/Widget.MaterialComponents.FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/mainlay"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="-28dp"
app:elevation="12dp"
app:borderWidth="0dp"
app:fabSize="normal"
app:srcCompat="#drawable/ic_directions_walk_white_18dp" />
AFAIK fab overrides elevation value. So there are two possible solutions:
1. You get source code of fab and change value of elevation
2. You create your own implementation.
I'd suggest you to use first solution.
Have you tried defining a custom style inherited from Widget.MaterialComponents.FloatingActionButton with your desired elevation, and set the custom style on your FAB instance?
Related
I use the following FloatingActionButton and I have set the background image using xml. How can I change the image programmatically in Kotlin? I want to replace the image 'image-color' with 'image-bw'.
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/image_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/image-color"
android:scaleType="center"
app:maxImageSize="56dp"
app:tint="#null"
app:layout_anchor="#id/bottom_appbar"
android:contentDescription="Categories" />
You can use the setImageDrawable function.
imageFab.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.your_drawable))
As title says, I don't know how to fix this issue. I read this problem but that was in 2018, I'm not very familiar with all those libraries and dependencies how it all works. But judging from my Declared Dependencies, from Android Studio, this is what I got:
I would like to add some kind of "Attach document" icon/image to the FAB. I tried to do this by adding a New Vector asset, but images do not appear in my drawable folder. How can I add a nice icon/image to my project, and set it to a FAB?
Here is XML:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:icon="#drawable/attache_file">
</com.google.android.material.floatingactionbutton.FloatingActionButton>
I found the solution, just add this below statement inside dimens.xml
<dimen name="design_fab_image_size" tools:override="true">56dp</dimen>
And must need to add app:tint="#null" inside your FAB design xml
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="#id/bottomBar"
app:srcCompat="#drawable/ic_logo"
app:tint="#null" />```
Happy to help :)
To use the com.google.android.material.floatingactionbutton.FloatingActionButton add the Material Components library:
implementation 'com.google.android.material:material:1.1.0'
Then use the app:srcCompat attribute:
<com.google.android.material.floatingactionbutton.FloatingActionButton
style="#style/Widget.MaterialComponents.FloatingActionButton"
app:srcCompat="#drawable/..."
.../>
Per the documentation you have to use android:src="#drawable/attache_file"
I want to show an action menu when I Press the ExtendedFloatingActionButton as in the image. My menu has 4 items, but I can't figure out how to easily make the FAb expand to display the actions.
I know ExtendedFloatingActionButton is a child class of MaterialButton, rather than FloatingActionButton, therefore working with it slightly differs from using the normal FAB
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
app:backgroundTint="#color/colorAccent"
android:contentDescription="Menu"
android:text="Menu"
app:iconTint="#color/card_background"
android:textColor="#color/background_card"
android:textStyle="bold"
app:icon="#drawable/ic_menu_black_24dp" />
I want to have a result like this:
I have found an easy implementation for a FloatingActionButton, but not for an ExtendedFloatingActionButton.
FAB transformation | animaiton-samples by android at GitHub
I have implemented floating action with list item and setting elevation from layout and run time on bind data as well. Then following issues occur:
fab elevation showing on first item only that is from xml resource I think.
setElevation() not working run time.
fab show()/hide() also not working with scale animation.
xml code is here:
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_btn_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/parentLayout"
android:layout_marginEnd="#dimen/fab_margin"
android:layout_marginRight="#dimen/fab_margin"
android:src="#drawable/ic_av_videocam"
app:elevation="#dimen/fab_shadow"
tools:targetApi="lollipop" />
This worked for me to change elevation:
fab.setCompatElevation(8f); //API>=21
You can try to use com.google.android.material.floatingactionbutton.FloatingActionButton instead of android.support.design.widget.FloatingActionButton. This will allow you to use show() and hide() methods.
Halloo guys I have problem here with coordinator layout. I have TextInputLayout and inside it I have editText. What I want is to show it on click on FAB on the left side and hide on click on FAB.
But I have always problem with edit text going below FAB:
Only way I was able to somehow do it is with using marginRight, see xml below. But is there any way to do it without that I think there must be better way.
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="#dimen/fab_normal_size"
android:layout_height="#dimen/fab_normal_size"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:fabSize="normal"
android:src="#drawable/ic_add_black_24dp" />
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_anchor="#id/fab"
app:layout_anchorGravity="left|center_vertical"
android:layout_marginRight="#dimen/fab_normal_size">
<EditText
android:id="#+id/input_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="banany"
android:text="testestes....." />
FAB is always over UI by design:
Floating action buttons are used for a special type of promoted
action. They are distinguished by a circled icon floating above the UI
and have special motion behaviors related to morphing, launching, and
the transferring anchor point.
I haven't checked how it is implemented so unless someone else come with better answer you can either check CoordinatorLayout and FAB sources to see what makes it hoovering over UI, or if time is short you simply put something that looks like FAB (either you use regular button with proper drawable, or 3rd party lib).
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_anchor="#id/fab"
app:layout_anchorGravity="left|center_vertical">
<EditText
android:id="#+id/input_txt"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:hint="banany"
android:text="testestes....." />
</android.support.design.widget.TextInputLayout>
Just try the above code, hope it suffice the purpose to some extent