在Android design support library中,SnackBar的使用:

Part 2 – Welcome Snackbar, Goodbye Toast!

BY PARESH MAYANI - JULY, 1ST 2015

Welcome to the second part of the Android design support library tutorial series. In the first part, we talked about Floating action button, its attributes and some of the FAB issues.

Today we will talk about another component “Snackbar”.

Welcome Snackbar, Goodbye Toast!

“Providing lightweight, quick feedback about an operation is a perfect opportunity to use a snackbar.”

Snackbar is another component available in design support library. Using Snackbar, we can show a quick message at the bottom (mostly) of the screen. It’s almost similar to Toast message, but a bit more flexible:

  • It automatically disappears after a time out or after user interaction on the screen.
  • It can contain an action, which is optional.
  • We can dismiss Snackbar by swiping it off the screen.
  • It is a context sensitive message and so those messages are part of the UI screen and appears above all other elements on the screen, not like Toast message overlying on a screen.
  • Only one snackbar can be displayed at a time.

Snackbar mostly inherits the same methods and attributes as the Toast, example LENGTH_LONG and LENGTH_SHORT attributes for setting the duration.

基本使用用法:

Snackbar.make(rootlayout, "Hello SnackBar!", Snackbar.LENGTH_SHORT)
.setAction("Undo", new View.OnClickListener() {
@Override
public void onClick(View v) {
// Perform anything for the action selected
}
})
.show();

  

简介:

Snackbar.make(view, message, duration)
.setAction(action message, click listener)
.show();

  

方法:

  • make() – To make a Snackbar to display a message
  • setAction() – To set an action
  • show() – To show a Snackbar

参考: android weekly

http://www.technotalkative.com/part-2-welcome-snackbar-goodbye-toast/

Toast的替代者Snackbar的更多相关文章

  1. Android开发2:事件处理及实现简单的对话框(Toast,AlertDialog,Snackbar,TextInputLayout的使用)

    前言 啦啦啦~又要和大家一起学习Android开发啦,博主心里好激动哒~ 在上篇博文中,我们通过线性布局和基础组件的使用,完成了一个简单的学生课外体育积分电子认证系统的界面,本篇博文,将和大家一起熟悉 ...

  2. 【转】Android M新控件之FloatingActionButton,TextInputLayout,Snackbar,TabLayout的使用

    Android M新控件之FloatingActionButton,TextInputLayout,Snackbar,TabLayout的使用 分类: Android UI2015-06-15 16: ...

  3. 【Android - MD】之Snackbar的使用

    Snackbar 是 Android 5.0 新特性--Material Design 中的一个控件,用来代替 Toast ,Snackbar与Toast的主要区别是:Snackbar可以滑动退出,也 ...

  4. 安卓高级6 SnackBar

    引言 文/李牧羊(简书作者) 原文链接:http://www.jianshu.com/p/2654e6bda3b1 著作权归作者所有,转载请联系作者获得授权,并标注"简书作者". ...

  5. <Android 基础(十一)> Snackbar

    介绍 Snackbars provide lightweight feedback about an operation. They show a brief message at the botto ...

  6. 【Android - 控件】之MD - Snackbar的使用

    Snackbar 是 Android 5.0 新特性——Material Design 中的一个控件,用来代替 Toast ,Snackbar与Toast的主要区别是:Snackbar可以滑动退出,也 ...

  7. Android Material Design简单使用

    吐槽 作为一个 Android developer,没有什么比拿着 UI 设计的一堆 iOS 风格的设计 来做需求更恶心的了,基本所有空间都要照着 iOS 来画一遍,Material Design 辣 ...

  8. Android Material Design(一)史上最全的材料设计控件大全

    主要内容: 本文将要介绍Material design和Support library控件,主要包括TextInputLayout.SwitchCompat.SnackBar.FloatingActi ...

  9. Codelab for Android Design Support Library used in I/O Rewind Bangkok session

    At the moment I believe that there is no any Android Developer who doesn't know about Material Desig ...

随机推荐

  1. SQL2012尝试读取或写入受保护的内存。这通常指示其他内存已损坏

    SQL2012尝试读取或写入受保护的内存.这通常指示其他内存已损坏 今天打开SQL2012,突然就连接不了数据库,一开始还以为是某个服务器崩溃了,结果试了好几个,都还是如此,弹出提示如下: 尝试读取或 ...

  2. JavaScript 字符串实用常用操作

    字符串截取1. substring()xString.substring(start,end)substring()是最常用到的字符串截取方法,它可以接收两个参数(参数不能为负值),分别是要截取的开始 ...

  3. 性能监控工具javamelody与spring的集成

    详细信息可以访问javamelody的官方网站 我在集成的过程中,一直出现commonHibernateDao的加载问题, 另外,根据官方文档,如果你的应用与monitoring-spring.xml ...

  4. UIPasteboard 粘贴板

    UIPasteboard *pasteboard = pasteboard.string = self.label.text;

  5. 关于新装ubuntu系统update失败和build-essential失败的解决办法

    我是12月4日在新电脑上的vmware-workstation 10 上安装的ubuntu14.04LTS,但安装后再校园环境下总是build-essential失败,上网一查,说是要先update, ...

  6. c#接口和new关键字和属性访问器基础收获

    1.interface 对于接口,一把我在项目中会这样使用: interface IStudent { string Name(); string GoSchool(); } 但是呢,这样有个不好的地 ...

  7. MYSQL区分大小写

    MYSQL区分大小写   1.linux下mysql安装完后是默认:区分表名的大小写,不区分列名的大小写: 2.用root帐号登录后,在/etc/my.cnf 中的[mysqld]后添加添加lower ...

  8. JQuery使用on绑定动态生成元素时碰到的问题

    今天在写界面时,希望对一些由JS代码动态添加的html标签进行事件绑定,使用了jquery 1.6+才提供的on函数.我的JQ版本是1.9.2. 以下这段代码是动态生成的. <div class ...

  9. Android Every day a new function:one

    扁平化按钮" 效果图: 代码: <?xml version="1.0" encoding="utf-8"?> <selector x ...

  10. 深入理解this对象

    最近一直在看js关于面向对象编程方面的东西,那么this肯定是需要一个被吃透 理解 同时灵活运用的对象 现在总结一下自己的学习成果: 我们可以用一句很形象的话来理解什么是this关键字? " ...