在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. 《think in python》学习-5

    think in python -5 think in python -5 条件和递归 求模操作符% 用于整数,可以计算出第一个操作数除以第二个操作数的余数 7%3 #结果是2 求模操作符%有很多用途 ...

  2. QRMaker生成二维码,支持中文

    QRMaker如果想支持中文,可以将中文转为UTF8,然后用InputDateB直接传入Byte() Option Explicit Private Declare Function WideChar ...

  3. RabbitMQ安装后启动出错:- unable to connect to epmd on blockstorage: timeout (timed out)

    具体出错信息如下: [root@blockstorage ~]# rabbitmqctl change_password guest RABBIT_PASS Changing password for ...

  4. api (三)文本字符输出 (转)

    在使用Win32编程时,我们常常要输出文本到窗口上,Windows所有的文本字符或者图形输出都是通过图形设备接口(GDI)进行的,Windows的三大核心组件之一的GDI32.dll封装了所有的文本和 ...

  5. js计时器。

    <html> <head> <title> Nonove js clock 时钟 </title> <script type="text ...

  6. Android 原生listview item伸展收缩效果

    Android原生listview做的一个item的伸缩效果.*永远不要让你老大有机会改需求 package com.example.yunkanglast; import java.io.Seria ...

  7. hadoop笔记之Hive的数据存储(视图)

    Hive的数据存储(视图) Hive的数据存储(视图) 视图(view) 视图是一种虚表,是一个逻辑概念:可以跨越多张表 既然视图是一种虚表,那么也就是说用操作表的方式也可以操作视图 但是视图是建立在 ...

  8. mysql函数操作

    <?php try{ $dbh = new PDO('mysql:dbname=testdb;host=localhost', 'mysql_user', 'mysql_pwd'); }catc ...

  9. Google Chrome浏览器的使用方法

    Google Chrome浏览器 [原文地址:http://www.cnblogs.com/QLeelulu/archive/2011/08/28/2156402.html ] 在Google Chr ...

  10. linux LVM 逻辑卷

    fdisk pvcreate vgcreate lvcreate 查看显示 创建 删除 扩容 激活 扫描查找 LV lvdisplay lvcreate lvremove lvextend lvcha ...