Skip to content

Instantly share code, notes, and snippets.

@bruno78
Last active October 28, 2018 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bruno78/e60f4c72dc3f337de38b63687c9b0913 to your computer and use it in GitHub Desktop.
Save bruno78/e60f4c72dc3f337de38b63687c9b0913 to your computer and use it in GitHub Desktop.
Solution for fab icon that disappears after click when using Coordinator layout
/***
* This method solves this problem:
* https://stackoverflow.com/questions/52133846/fab-icon-disappers-after-click
* https://stackoverflow.com/questions/49587945/setimageresourceint-doesnt-work-after-setbackgroundtintcolorlistcolorstateli/52158081#52158081
* @param resource
* Implement this method inside of the fab click function
*/
private void changeFab(int resource) {
mFabButton.hide();
mFabButton.setImageResource(resource);
mFabButton.show();
}
// Kotlin version
fun FloatingActionButton.changeFab(@ColorRes colorRes: Int, @DrawableRes imageRes: Int) {
hide()
backgroundTintList = ContextCompat.getColorStateList(context, colorRes)
setImageResource(imageRes)
show()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment