Clans / FloatingActionButton

Android Floating Action Button based on Material Design specification
Apache License 2.0
5.22k stars 1.13k forks source link

There is no method to get button count #419

Open ankitgoyal1009 opened 7 years ago

ankitgoyal1009 commented 7 years ago

I was working on my project and got a requirement that if there is no buttons in fab menu don't show it so when I looked into class there is no method to get button count in FabMenu class. For now I have checked childView count and if it is more then 2 then hide fab menu.

NikolayKul commented 7 years ago

@ankitgoyal1009 You've probably meant "less then 2 childs then hide fab menu". Anyway you can always count FABs yourself:

public class MyFabMenu extends FloatingActionMenu {
...
  private int getFabCount() {
    int res = 0;
    for (int i = 0; i < getChildCount(); ++i) {
      final View child = getChildAt(i);
      if (child instanceof FloatingActionButton) {
        res++
      }
    }
    return --res;  // decrement for fab menu button
  }
}