Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement a single FAB across numerous fragments?

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

like image 948
Mullazman Avatar asked Mar 16 '23 14:03

Mullazman


1 Answers

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);
like image 89
JF YOBOUE Avatar answered Apr 29 '23 08:04

JF YOBOUE