一.实例图
二.
导入依赖库:
compile 'com.android.support:design:23.2.0' (这个库还可以用Flaottingbutton)
1.可以滑动删除该弹窗
布局:需要关联这个布局
<android.support.design.widget.CoordinatorLayout
android:id="@+id/layoutRoot"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:id="@+id/btnFloatingAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:src="@drawable/ic_plus"
app:fabSize="normal"
app:borderWidth="0dp"
android:layout_marginBottom="@dimen/fab_margin_bottom"
android:layout_marginRight="@dimen/fab_margin_right"/>
</android.support.design.widget.CoordinatorLayout>
如果不需要滑动删除窗口,可以用任意控件绑定sanckbar.但不可以用scroView.因为scrollerView只能有一个孩子,而绑定的方式是add方法
调用
layoutRoot = (CoordinatorLayout) findViewById(R.id.layoutRoot);
btnFab = (FloatingActionButton) findViewById(R.id.btnFloatingAction);
btnFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Snackbar.make(layoutRoot, "Hello SnackBar!", Snackbar.LENGTH_SHORT)
.setAction("点我", new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this,DetailActivty.class));
}
})
.show();