A library that builds on the AppCompat Design Library and provides additional common components such as AccountHeaderView, FloatingActionMenu, CircleImageView, Picker Dialogs, FlexibleToolbarLayout, Delightful Detail Drawables and TypefaceCompat.
Apache License 2.0
304
stars
42
forks
source link
How to use implement the listener in Activity for click on Add Flab? #25
Sorry for the late response. It depends on which floating action button you want to attach a click listener to:
If you want a click listener for the normal FABs, just add a View.OnClickListener as you would normally do for any other button:
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
// called when the button is clicked
}
};
FloatingActionButton button = findViewById(R.id.fab);
button.setOnClickListener(listener);
If you want a click listener for the main FAB, you can use the FloatingActionMenu.OnFloatingActionsMenuUpdateListener which gets called when the user toggles the menu:
FloatingActionMenu.OnFloatingActionsMenuUpdateListener listener = new FloatingActionMenu.OnFloatingActionsMenuUpdateListener() {
@Override
public void onMenuExpanded() {
// called when the menu has been expanded
}
@Override
public void onMenuCollapsed() {
// called when menu has been collapsed
}
}
FloatingActionMenu menu = findViewById(R.id.fam);
menu.setOnFloatingActionsMenuUpdateListener(listener);
If you really need full control over the click listener for the main FAB, you can just set your own View.OnClickListener and toggle the menu there:
final FloatingActionMenu menu = findViewById(R.id.fam);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
// called when the main button is clicked
menu.toggle();
}
};
FloatingActionButton main = findViewById(R.id.fab_main);
main.setOnClickListener(listener);
Sorry for the late response. It depends on which floating action button you want to attach a click listener to:
View.OnClickListener
as you would normally do for any other button:If you want a click listener for the main FAB, you can use the
FloatingActionMenu.OnFloatingActionsMenuUpdateListener
which gets called when the user toggles the menu:View.OnClickListener
and toggle the menu there: