Reputation: 509
I'm interested in implementing a FloatingActionButton or FAB across a number of fragments. When the fragment changes, the FAB's icon should change and the button should obviously then do something pertaining to that specific fragment, however for a seamless display, the FAB is located within the Main Activity and not per-fragment.
What's the most proper and/or efficient way of doing this?
I can't wrap my head around it.. I've tried to implement listeners in the Fragment, for the click in the Activity, but it's saying the listeners are Cyclical
Thanks
Upvotes: 4
Views: 1434
Reputation: 79
You can get the Floating Action Button in your fragments e.g in onCreate
method of fragment by doing something that
FloatingActionButton fab = (FloatingActionButton)this.getActivity().findViewById(R.id.fab);
Upvotes: 7