private static Toast toast;
@SuppressLint("ShowToast")
public static void showShortToast(String msg) {
if (MyApplication.getInstance() != null) {
Run.onUiAsync(new Action() {
@Override
public void call() {
if (toast == null) {
toast = Toast.makeText(MyApplication.getInstance(), msg, Toast.LENGTH_SHORT);
toast.setText(msg);
} else {
toast.setText(msg);
}
toast.show();
}
});
}
}
@SuppressLint("ShowToast")
public static void showShortToastCenter(String msg) {
if (MyApplication.getInstance() != null) {
Run.onUiAsync(new Action() {
@Override
public void call() {
if (toast == null) {
toast = Toast.makeText(MyApplication.getInstance(), msg, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.setText(msg);
} else {
toast.setText(msg);
}
toast.show();
}
});
}
}
|