Light - 优雅的Snackbar

Light

Light

优雅地使用Snackbar. 灵感来源于 Toasty.

截图

success

info

normal

warning

error

custom

下载

Gradle

将下面的代码添加至你的 build.gradle 文件 (不是 module 下的 build.gradle 文件,点击这里查看示例)。

allprojects {
    repositories {
        jcenter()
    }
}

将下面的代码添加至 module 下的 build.gradle文件:

dependencies {
    // 这里放其他依赖
    compile 'io.github.tonnyl:light:1.0.0'
}

Maven

<dependency>
  <groupId>io.github.tonnyl</groupId>
  <artifactId>light</artifactId>
  <version>1.0.0</version>
  <type>pom</type>
</dependency>

使用方法

每一个方法都将返回一个 Snackbar 对象,所以你也可以进行自定义。 不要忘记调用 show() 方法!

  • 展示用于显示成功信息的Snackbar:
Light.success(fab, "Success", Light.LENGTH_SHORT)
        .setAction("Action", new View.OnClickListener() {
            @Override
            public void onClick(View v) {         
                Toast.makeText(MainActivity.this, "Hello, Light!", Toast.LENGTH_SHORT).show();
            }
        })
        .show();
// 或者调用
Light.make(fab, "Success", Light.TYPE_SUCCESS, Light.LENGTH_SHORT).show();
  • 展示用于显示普通信息的 Snackbar:
Light.info(fab, "Info", Light.LENGTH_SHORT).show();
// 或者调用
Light.make(fab, "Info", Light.TYPE_INFO, Light.LENGTH_SHORT).show();
  • 展示用于显示警告信息的Snackbar:
Light.warning(fab, "Warning", Light.LENGTH_SHORT).show();
// 或者调用
Light.make(fab, "Warning", Light.TYPE_WARNING, Light.LENGTH_SHORT).show();
  • 展示用于显示错误信息的 Snackbar:
Light.error(fab, "Error", Light.LENGTH_SHORT).show();
// 或者调用
Light.make(fab, "Error", Light.TYPE_ERROR, Light.LENGTH_SHORT).show();
  • 展示普通的 Snackbar:
Light.normal(fab, "Normal", Light.LENGTH_SHORT).show();
// 或者调用
Light.make(fab, "Normal", Light.TYPE_NORMAL, Light.LENGTH_SHORT).show();
  • 你也可以直接创建一个自定义设计样式的Snackbar:
Light.make(
        fab, // The view to find a parent from.
        "Awesome Snackbar", // The text to show.
        R.drawable.ic_album_white_24dp, // The left icon of text to show.
        R.color.color_cyan, // The background color of Snackbar.
        android.R.color.white, // The color of text to show.
        Light.LENGTH_INDEFINITE, // How long to display the message.
        R.drawable.ic_done_all_white_24dp, // The left icon of action text.
        R.color.colorAccent) // The color of action text.
        .setAction("Done all", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Do whatever you want to do.
                Toast.makeText(MainActivity.this, "Hello, Light!", Toast.LENGTH_SHORT).show();
            }
        })
        .show();

其他

你也直接向Light传递formatted text!

合并请求

你有新的点子或者找到了一个bug?不用犹豫,创建一个 issue 并发起一个 pull request 吧。

许可证

Copyright 2017 lizhaotailang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.