android悬浮按钮demo记录

1.导包,框架来源:https://github.com/futuresimple/android-floating-action-button/blob/master/sample/src/main/res/layout/activity_main.xml

dependencies {
    implementation 'com.getbase:floatingactionbutton:1.10.0'
  
}

2.xml文件




    

        

        

    






设置按钮尺寸和弹出方向,默认应是向上

fab:fab_addButtonSize="mini"
fab:fab_expandDirection="down"

3.activity和监听

public class SecondActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        initButtons();
    }

    public void initButtons() {
        FloatingActionButton actionButton = findViewById(R.id.action_a);
        FloatingActionButton button = findViewById(R.id.action_b);

        actionButton.setOnClickListener(new buttonClick());//给按钮添加监听
        button.setOnClickListener(new buttonClick());

    }
    //监听类
    public class buttonClick implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.action_a:
                    System.out.println("点了个a");
                    break;
                case R.id.action_b:
                    System.out.println("点了个b");
                    break;
                default:
                    break;
            }
        }
    }

}

4.效果图

android悬浮按钮demo记录_第1张图片android悬浮按钮demo记录_第2张图片

你可能感兴趣的:(demo)