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();
}
});
}
}
Android 自定义Toast工具类
最新推荐文章于 2024-04-26 09:14:08 发布