[Android Material Design]组件01 - FloatActionButton

效果图

FloatActionButton

关键代码

xml布局文件如下

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="16dp"
    android:src="@drawable/ic_done"
    app:elevation="8dp"
    app:fabSize="mini"
    android:contentDescription="fab" />

kotlin逻辑代码如下:

val fab = findViewById<FloatingActionButton>(R.id.fab)
fab.setOnClickListener { v: View ->
    Snackbar.make(v, "I am Snackbar", Snackbar.LENGTH_LONG)
        .setAction("retry") {
            Toast.makeText(this, "click me", Toast.LENGTH_LONG).show()
        }.show()
    }

FloatingActionButton常见属性含义如下:

属性含义
app:backgroundTint设置背景颜色
app:rippleColor设置点击时的背景颜色
app:elevation默认状态下的阴影大小
app:fabSize设置大小,normal对应大小为56dp,mini对应大小为40dp
app:layout_anchor设置指定控件为参照点的位置
app:pressedTranslationZ设置点击时FAB的阴影大小

app:fabSize设置为mini时如下:
mini大小
app:fabSize设置为normal时如下:
默认大小
自定义大小如下:
自定义大小

源码地址

https://github.com/yurensan/MaterialDesignDemo

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值