Kevin Learn Android:FloatingActi
2021-06-29 本文已影响0人
Kevin_小飞象
16.jpg
前言
04.png引入 material 包:
implementation 'com.google.android.material:material:1.2.1'
属性
属性 | 含义 |
---|---|
backgroundTint | 背景颜色 |
elevation | 描边颜色 |
pressedTranslationZ | 点击状态下的阴影大小 |
borderWidth | 边宽,上下兼容,设置0dp |
rippleColor | 点击时的背景颜色 |
layout_anchor | 设置锚点,即以哪个控件为参照点设置位置。 |
layout_anchorGravity | 设置相对锚点的位置,值有 bottom、center、right、left、top等 |
fabSize | 按钮大小,normal和mini |
使用
- 布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:layout_gravity="bottom|end"
android:src="@mipmap/ic_fab_add"
android:scaleType="center"
app:backgroundTint="@color/btn_color"
app:backgroundTintMode="src_in"
app:elevation="5dp"
app:rippleColor="@color/gray_pressed"
app:fabSize="auto"
app:pressedTranslationZ="10dp"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
- 在 activity 使用
public class MainActivity extends BaseActivity {
@Override
public int getLayoutId() {
return R.layout.activity_main;
}
@Override
public void initView() {
}
@OnClick(R.id.fab_add)
public void onClicked() {
ToastUtils.showToast(this,"hello fab");
}
}