FloatingActionButton 字面意识可理解为:悬浮的意图按钮, 个人在使用后将其理解为: 一个圆形的图片按钮,因为它不支持设置文本
- 引入
implementation 'com.google.android.material:material:1.4.0'
- 使用
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:src="@drawable/ic_launcher_foreground"
app:fabSize="normal"
app:rippleColor="@color/black" />
- 属性
属性 | 描述 |
---|---|
android:src | 中心图片 |
app:backgroundTint | 背景色 |
app:rippleColor | 按压水波纹颜色 |
app:fabSize | normal (56dp) mini(40dp) |
- FloatingActionButton的显示(show )与隐藏(hide)
public class MainActivity extends AppCompatActivity {
boolean isShow = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main1);
FloatingActionButton fab = findViewById(R.id.fab);
findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isShow) {
isShow = false;
fab.hide();
} else {
isShow = true;
fab.show();
}
}
});
}
}