0%

FloatingActionButton&SnackBar

简介

FloatingActionButton:悬浮按钮
SnackBar:屏幕底部快速弹出消息

一段代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//底部小窗SnackBar
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_SHORT)
.setAction("执行动作", new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"Snackbar 动作",Toast.LENGTH_SHORT).show();
}
}).show();
}
});
1
2
3
4
5
6
7
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email"/>