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 af
From https://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html
As this class descends from ImageView, you can control the icon which is displayed via setImageDrawable(Drawable).
Or you can use setImageResource():
fab.setImageResource(R.drawable.ic_shopping_cart_white);
Add the property
fab:fab_icon="@drawable/fab_expand"
in the xml where you initialized the floating action menu.
I faced same issue recently, I tried with following option
fab:fab_icon="@drawable/icon"
and
android:src="@drawable/icon" // change backgroung icon
even tried programmatically
fab_menu_btn.setImageResource();
Nothing worked.
Solution: In app's build.gradle file replace
compile 'com.getbase:floatingactionbutton:1.10.0'
to
compile 'com.github.toanvc:floatingactionmenu:0.8.9'
In .xml file Use:
<toan.android.floatingactionmenu.FloatingActionsMenu
</toan.android.floatingactionmenu.FloatingActionsMenu>
In activity File:
floatingActionsMenu.setIcon(getResources().getDrawable(R.mipmap.icon));
Thanks
In the Material design version:
defaultConfig {
vectorDrawables.useSupportLibrary = true // For srcCompat
}
dependencies {
implementation 'com.google.android.material:material:<version>'
}
app:srcCompat="@drawable/ic_google"
app:tint="@color/colorGoogle"
More documentation: https://material.io/develop/android/components/floating-action-button/
you can use this in your .XML :
android:src="@drawable/icon" // change backgroung icon
app:backgroundTint="@color/icons" // change background color
use this in code:
mFloatingActionButton.setImageResource(R.drawable/icon2);
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!