如何在android中制作toast消息的接口?
我正在尝试用一些方法来创建接口,比如showtoos(),我将在需要的地方用多个类来实现它。我如何才能做到这一点 代码:-如何在android中制作toast消息的接口?,android,Android,我正在尝试用一些方法来创建接口,比如showtoos(),我将在需要的地方用多个类来实现它。我如何才能做到这一点 代码:- public interface Test { void showToast(); }使用我的代码片段。 首先在任何Util/Helper类中创建一个方法 public static void toastOnMain(final String message, final int toastLength) { if (context == null) {
public interface Test {
void showToast();
}使用我的代码片段。
首先在任何Util/Helper类中创建一个方法
public static void toastOnMain(final String message, final int toastLength) {
if (context == null) {
return;
}
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, message, toastLength).show();
}
});
}
然后打电话
Classname.toastOnMain("Hello World");
像这样使用它
Logger.shortToast(this,"HELLO");
Logger.shortToast(this,"HELLO");