<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">系统自带的Toast,显示的有点小了,而现在的屏幕越来越大,位置也是固定了。</span>
github上找了一个第三方的SuperToast库使用。
SuperToast st = SuperToast.create(ct, "文章发表成功", SuperToast.Duration.MEDIUM);
st.setIcon(R.drawable.ic_launcher, IconPosition.LEFT);
st.setBackground(Background.ORANGE);
st.setAnimations(Animations.FLYIN);
st.setTextColor(ct.getResources().getColor(android.R.color.black));
st.setTextSize(SuperToast.TextSize.MEDIUM);
st.setGravity(Gravity.CENTER, 0, 0);
st.show();
简单的归纳功能:
(1)设置显示的时长,选项比较多;
(2)可以设置显示icon,及选择icon的位置;
(3)设置字体大小,字体颜色;
(4)设置背景颜色;
(5)设置位置(可以设置任意位置,这个非常不错);
(6)设置动画效果;
简单封装一下:
package com.test.app;
import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import com.github.johnpersano.supertoasts.SuperToast;
public class SuperToastUtils {
public static void showShort(Context ct, int resId) {
showShort(ct, ct.getResources().getString(resId));
}
public static void showShort(Context ct, String msg) {
show(ct, msg, SuperToast.Duration.SHORT);
}
public static void showLong(Context ct, int resId) {
showLong(ct, ct.getResources().getString(resId));
}
public static void showLong(Context ct, String msg) {
show(ct, msg, SuperToast.Duration.LONG);
}
public static void show(Context ct, String msg, int duration) {
SuperToast st = SuperToast.create(ct, msg, duration);
st.setTextSize(SuperToast.TextSize.MEDIUM);
st.setTextColor(Color.WHITE);
st.setGravity(Gravity.CENTER, 0, 0);
st.show();
}
}