一. 前篇
Toast是我們常用的一個小型提示語框,但系統預設的Toast真的很寒酸,檢視第三方的時候看到了Toasty,簡單易上手,
分分鐘就能用,接下來我們一起看看。
二. 配置
(1)在我們的根目錄(最外層的build.gradle)中添加
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" } //添加這一條
}
}
(2)在我們的項目(model)中添加
compile 'com.github.GrenderG:Toasty:1.1.3'
三. 實作
這裡就隻把方法貼出來了,設定按鈕點選事件,然後引用這些方法就可以實作對應的效果了,很簡單吧
/**
* 錯誤Toast:
*/
private void showError() {
Toasty.error(this, btn1.getText().toString(), Toast.LENGTH_SHORT, true).show();
}
/**
* 成功Toast:
*/
private void showSuccess() {
Toasty.success(this, btn2.getText().toString(), Toast.LENGTH_SHORT, true).show();
}
/**
* 資訊Toast:
*/
private void showInfo() {
Toasty.info(this, btn3.getText().toString(), Toast.LENGTH_SHORT, true).show();
}
/**
* 警告Toast:
*/
private void showWarning() {
Toasty.warning(this, btn4.getText().toString(), Toast.LENGTH_SHORT, true).show();
}
/***
*通常的Toast
*/
private void showUsual() {
Toasty.normal(this, btn5.getText().toString(), Toast.LENGTH_SHORT).show();
}
/**
* 帶有圖示的常用Toast:
*/
private void showIcon() {
Toasty.normal(this, btn6.getText().toString(), R.mipmap.ic_launcher).show();
}
/**
* 建立自定義Toasts :
*/
private void showCustom() {
Toasty.custom(this, btn7.getText().toString(),
R.mipmap.ic_launcher, Color.BLUE, Color.RED, Toast.LENGTH_SHORT, true, true).show();
}
每天進步一點點!