How to disable RecyclerView Items from clicking

后端 未结 9 826
迷失自我
迷失自我 2020-12-31 04:00

I am using Floating Action Button. I want to disable Recyclerview Items from Clicking when i press FAB button. I tried this method but not working setClickable(true);<

相关标签:
9条回答
  • 2020-12-31 04:43

    You can simply use recursion to disable/enable clicks on view

     public static void setClickable(View view, boolean clickable) {
            if (view != null) {
                if (view instanceof ViewGroup) {
                    ViewGroup viewGroup = (ViewGroup) view;
                    for (int i = 0; i < viewGroup.getChildCount(); i++) {
                        setClickable(viewGroup.getChildAt(i), clickable);
                    }
                }
                view.setClickable(clickable);
            }
        }
    
    0 讨论(0)
  • 2020-12-31 04:46
    1. In the xml file, set the layout_width and layout_height for FloatingActionMenu as match_parent and set clickable as false :

          android:layout_width="match_parent "
          android:layout_height="match_parent "
          android:clickable="false"
      
    2. In your java class,

      floatMenu.setOnMenuToggleListener(new FloatingActionMenu.OnMenuToggleListener() {
              @Override
              public void onMenuToggle(boolean opened) {
                  if (opened) {
                     floatMenu.setClickable(true);
                  } else {
                       floatMenu.setClickable(false);
                  }
              }
          });
      

    This should work.

    0 讨论(0)
  • 2020-12-31 04:47

    You need to set the click listener to every FloatingActionButton.

    see this issue on library

    0 讨论(0)
提交回复
热议问题