Dynamically added FloatingActionButton does not adopt behavior to move with the Snackbar

367 views Asked by At

I'm trying to add a FloatingActionButton to a CoordinatorLayout in my Activity's onCreate(). This is basically working. It receives Coordinator.LayoutParams with gravity = BOTTOM | RIGHT. When the Snackbar (attached to the same coordinator) pops in, it underlays the button though.

If I embed the FloatingActionButton into the coordinator via xml it works as advertised.

The embedded button and the dynamically added one are based on the same xml source, added via <include /> (working) and via addView( inflate( ... ) ) (not working). The view hierarchy in the debugging tool is identical.

One strange thing I noticed here, is that in onCreate(), after inflating/adding, the behavior of the fab is null. Before the Snackbar appears, it magically received a FloatingActionButton.Behavior.

Manually setting the FloatingActionButton.Behavior while adding the view did not help.

It would help me a lot to understand what is going on, if I could access the source code of the design library, but it seems to be not available yet.

1

There are 1 answers

0
tymm On BEST ANSWER

By now inflating a FloatingActionButton in code, when there is a Snackbar in the same CoordinatorLayout, should work just fine.