t调试
This commit is contained in:
@@ -2,6 +2,8 @@ package com.sw.plate.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -30,18 +32,23 @@ public class ToastUtils {
|
||||
* @param text the text
|
||||
*/
|
||||
public static void showToast(String text) {
|
||||
Context context = App.getContext();
|
||||
if (toast == null) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.toast_bg, null);
|
||||
textCenterView = view.findViewById(R.id.toast_tv);
|
||||
toast = new Toast(context);
|
||||
toast.setGravity(Gravity.CENTER, 0, 20);
|
||||
toast.setDuration(Toast.LENGTH_SHORT);
|
||||
toast.setView(view);
|
||||
}
|
||||
runOnMainThread(()->{
|
||||
Context context = App.getContext();
|
||||
if (toast == null) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.toast_bg, null);
|
||||
textCenterView = view.findViewById(R.id.toast_tv);
|
||||
toast = new Toast(context);
|
||||
toast.setGravity(Gravity.CENTER, 0, 20);
|
||||
toast.setDuration(Toast.LENGTH_SHORT);
|
||||
toast.setView(view);
|
||||
}
|
||||
textCenterView.setText(text);
|
||||
toast.show();
|
||||
});
|
||||
}
|
||||
|
||||
textCenterView.setText(text);
|
||||
toast.show();
|
||||
public static void runOnMainThread(Runnable runnable) {
|
||||
new Handler(Looper.getMainLooper()).post(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,32 +57,36 @@ public class ToastUtils {
|
||||
* @param text the text
|
||||
*/
|
||||
public static void showToast(String text, int duration) {
|
||||
Context context = App.getContext();
|
||||
if (toast == null) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.toast_bg, null);
|
||||
textCenterView = view.findViewById(R.id.toast_tv);
|
||||
toast = new Toast(context);
|
||||
toast.setGravity(Gravity.CENTER, 0, 20);
|
||||
toast.setView(view);
|
||||
}
|
||||
runOnMainThread(()-> {
|
||||
Context context = App.getContext();
|
||||
if (toast == null) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.toast_bg, null);
|
||||
textCenterView = view.findViewById(R.id.toast_tv);
|
||||
toast = new Toast(context);
|
||||
toast.setGravity(Gravity.CENTER, 0, 20);
|
||||
toast.setView(view);
|
||||
}
|
||||
|
||||
textCenterView.setText(text);
|
||||
toast.setDuration(duration);
|
||||
toast.show();
|
||||
textCenterView.setText(text);
|
||||
toast.setDuration(duration);
|
||||
toast.show();
|
||||
});
|
||||
}
|
||||
|
||||
public static void showLongToast(String text) {
|
||||
Context context = App.getContext();
|
||||
if (toast == null) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.toast_bg, null);
|
||||
textCenterView = view.findViewById(R.id.toast_tv);
|
||||
toast = new Toast(context);
|
||||
toast.setGravity(Gravity.TOP, 0, 20);
|
||||
toast.setDuration(Toast.LENGTH_LONG);
|
||||
toast.setView(view);
|
||||
}
|
||||
textCenterView.setText(text);
|
||||
showMyToast(toast, 1000000 * 30);
|
||||
runOnMainThread(()-> {
|
||||
Context context = App.getContext();
|
||||
if (toast == null) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.toast_bg, null);
|
||||
textCenterView = view.findViewById(R.id.toast_tv);
|
||||
toast = new Toast(context);
|
||||
toast.setGravity(Gravity.TOP, 0, 20);
|
||||
toast.setDuration(Toast.LENGTH_LONG);
|
||||
toast.setView(view);
|
||||
}
|
||||
textCenterView.setText(text);
|
||||
showMyToast(toast, 1000000 * 30);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user