如何通过代码更改扩展的浮动操作按钮图标?

how to change Extended floating action button Icon by code?

我有一个 Extended Floating Action Button 我想以编程方式更改图标

你需要使用setIconResource()方法

示例代码

extendedFloatingActionButton.setIconResource(R.drawable.ic_favorite)

ExtendedFloatingActionButton class 来自 MaterialButton, so you can control the icon which is displayed using setIcon()。所以你可以这样做:

extendedFab.icon = getDrawable(R.drawable.icon)