I used this library https://github.com/futuresimple/android-floating-action-button. How can I change the image of the main button? I want to change the button image right after selecting one of the smaller buttons.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
you can use this in your .XML :
use this in code:
Add the property
in the xml where you initialized the floating action menu.
I faced same issue recently, I tried with following option
and
even tried programmatically
Nothing worked.
Solution: In app's build.gradle file replace
to
In .xml file Use:
In activity File:
Thanks
From https://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html
Or you can use setImageResource():
I had the same problem and I managed to create my own solution. Maybe some else founds it also useful. I have posted the complete answer to another question (How to set an icon to getbase FloatingActionsMenu) but this part posted here is relevant to the question in dynamically changing the main menu button picture/image when one of the sub buttons is chosen. In this case, you need o combine the answer from the "linked question" and the answer below.
In order to change the icon on the menu button when you choose a floatingActionButton it can be implemented like this:
Create menu button in xml file, create floating button(s) on .java file (programmatically) set menu button (color button, color pressed button and image). Then simply add all buttons to the menu button. You can also deactivate the animation of the menu button by simply commenting out the code in
FloatingActionsMenu
class.Then every time that you create a button, sample:
See the answer posted on the link on how to configure the classes and define the menu button and floating button(s).
So the important part to notice here is:
This method you need to add in the
FloatingActionsMenu
class. Simply you call the method after on every floatingActionButton you want to update the image.More information you can find on the link that I have posted. So when you click one of the floatingActionButton(s).
For the moment the color on the menu button is not updating correctly but I am working on it if I find a solution I will update the answer here as well. Hope this helps, happy coding.
Unfortunately with this library you can't change the icon from the menu (see issues from this library from more info)
That is why I dropped this library to use a way more flexible one! It is originally a fork but it is now more advanced ;)
Here is the link
Enjoy!