一个可以展示多个悬浮按钮的菜单的使用(FloatingActionButton)

GitHub 地址

附上作者的博客地址。作者写的比较详细

我写的比较精简

  implementation 'com.azhon:suspension-fab:1.1.0'
private  FabAttributes fab1,fab2,fab3; //悬浮按钮的三个菜单

  SuspensionFab fabTop = (SuspensionFab)view.findViewById(R.id.fab);

//构建展开按钮属性
         fab1= new FabAttributes.Builder()
                .setBackgroundTint(Color.parseColor("#FFFFFF"))//菜单的背景颜色
                .setSrc(getResources().getDrawable(R.drawable.ic_shuaxin))//菜单图标
                .setFabSize(FloatingActionButton.SIZE_MINI) //菜单大小
                .setPressedTranslationZ(10)
                .setTag(1)
                .build();
         fab2= new FabAttributes.Builder()
                .setBackgroundTint(Color.parseColor("#FFFFFF"))
                .setSrc(getResources().getDrawable(R.drawable.ic_clock))
                .setFabSize(FloatingActionButton.SIZE_MINI)
                .setPressedTranslationZ(10)
                .setTag(2)
                .build();
        fab3= new FabAttributes.Builder()
                .setBackgroundTint(Color.parseColor("#FFFFFF"))
                .setSrc(getResources().getDrawable(R.drawable.ic_top))
                .setFabSize(FloatingActionButton.SIZE_MINI)
                .setPressedTranslationZ(10)
                .setTag(3)
                .build();

//添加菜单
        fabTop.addFab(fab1, fab2,fab3);
        fabTop.setAnimationManager(new FabAlphaAnimate(fabTop));
//设置菜单点击事件
        fabTop.setFabClickListener(this);

菜单的点击事件


    @Override
    public void onFabClick(FloatingActionButton fab, Object tag) {
       if (tag.equals(1)){
         //第一个菜单的点击事件
       }else if (tag.equals(2)){
         //第二个菜单的点击事件
       }else  if (tag.equals(3)){
           //第三个菜单的点击事件
       }
    }

 

猜你喜欢

转载自blog.csdn.net/qq_41334474/article/details/84546344