自定义Toast时间(ms级别)
/*自定义Toast时间实现(ms级别)*/
public static void showToast(final Activity activity, final String word, final long time){
activity.runOnUiThread(new Runnable() {
public void run() {
final Toast toast = Toast.makeText(activity, word, Toast.LENGTH_LONG);
toast.show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
toast.cancel();
}
}, time);
}
});
}
显示期间重复触发叠加显示的解决
public class Util {
private static Toast toast;
public static void showToast(Context context,
String content) {
if (toast == null) {
toast = Toast.makeText(context,
content,
Toast.LENGTH_SHORT);
} else {
toast.setText(content);
}
toast.show();
}
}
参照郭神的:
https://blog.youkuaiyun.com/guolin_blog/article/details/51336415