26 lines
744 B
Java
26 lines
744 B
Java
|
package com.example.myapplication.Tool;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.os.Handler;
|
||
|
import android.os.Looper;
|
||
|
import android.widget.Toast;
|
||
|
|
||
|
public class BackgroundToast {
|
||
|
private static Handler handler;
|
||
|
private static Toast currentToast;
|
||
|
|
||
|
public static void show(final Context context, final String message) {
|
||
|
if (handler == null) {
|
||
|
handler = new Handler(Looper.getMainLooper());
|
||
|
}
|
||
|
|
||
|
handler.post(() -> {
|
||
|
if (currentToast != null) {
|
||
|
currentToast.cancel();
|
||
|
}
|
||
|
|
||
|
currentToast = Toast.makeText(context.getApplicationContext(), message, Toast.LENGTH_SHORT);
|
||
|
currentToast.show();
|
||
|
});
|
||
|
}
|
||
|
}
|