快速弹出窗口(一):SnackBar的使用

一.实例图


二.

导入依赖库:
compile 'com.android.support:design:23.2.0'   (这个库还可以用Flaottingbutton)
1.可以滑动删除该弹窗
布局:需要关联这个布局
  
  
    
    
  1. <android.support.design.widget.CoordinatorLayout
  2. android:id="@+id/layoutRoot"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent">
  5. <android.support.design.widget.FloatingActionButton
  6. android:id="@+id/btnFloatingAction"
  7. android:layout_width="wrap_content"
  8. android:layout_height="wrap_content"
  9. android:layout_gravity="bottom|right"
  10. android:src="@drawable/ic_plus"
  11. app:fabSize="normal"
  12. app:borderWidth="0dp"
  13. android:layout_marginBottom="@dimen/fab_margin_bottom"
  14. android:layout_marginRight="@dimen/fab_margin_right"/>
  15. </android.support.design.widget.CoordinatorLayout>

如果不需要滑动删除窗口,可以用任意控件绑定sanckbar.但不可以用scroView.因为scrollerView只能有一个孩子,而绑定的方式是add方法
 
 
调用
  
  
    
    
  1. layoutRoot = (CoordinatorLayout) findViewById(R.id.layoutRoot);
  2. btnFab = (FloatingActionButton) findViewById(R.id.btnFloatingAction);
  3. btnFab.setOnClickListener(new View.OnClickListener() {
  4. @Override
  5. public void onClick(View v) {
  6. Snackbar.make(layoutRoot, "Hello SnackBar!", Snackbar.LENGTH_SHORT)
  7. .setAction("点我", new View.OnClickListener() {
  8. @Override
  9. public void onClick(View v) {
  10. startActivity(new Intent(MainActivity.this,DetailActivty.class));
  11. }
  12. })
  13. .show();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值