Android中FloatingActionButton的基本使用

Android中 FloatingActionButton的简单使用

首先上悬浮效果图如图所示:
首先上悬浮效果图如图所示:

实现效果的步骤很简单,如下:

1.直接在app的build.gradle中添加引用 即可 
      compile 'com.android.support:design:25.3.1'
2.在XML布局中设置想要的悬浮样式

 <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_anchor="@id/view_pager"//依附于某个控件
        app:srcCompat="@drawable/tel"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="55dp"
        android:layout_marginRight="3dp"
        android:layout_alignParentEnd="true" />
        注:这里我们使用了app的属性,则需要在根容器中添加属性
        xmlns:app="http://schemas.android.com/apk/res-auto" 

3.在代码中实现悬浮按钮相对应的点击事件

 FloatingActionButton fab =(FloatingActionButton)findViewById(R.id.fab);

 fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //相关操作
            }
        });

具体操作就是上面这些,完毕。。。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值