public static Toast getSingleToast(String text, int duration) { if (mToast == null) { mToast = Toast.makeText(context, text, duration); } else { mToast.setText(text); } return mToast; }
/** * 单例 toast * * @param string */ public static void makeText(Context context, String string) { if (mToast == null) { mToast = Toast.makeText(context, string, Toast.LENGTH_SHORT); } mToast.setText(string); mToast.show(); }
static void toastShowShort(Context context, String msg) { if (mToast == null) { mToast = Toast.makeText(context.getApplicationContext(), msg, Toast.LENGTH_SHORT); } else { mToast.setText(msg); } mToast.show(); }
/** * 短时间显示Toast */ public static void showShort(Context context, CharSequence message) { if (null == toast) { toast = Toast.makeText(context, message, Toast.LENGTH_SHORT); // toast.setGravity(Gravity.CENTER, 0, 0); } else { toast.setText(message); } toast.show(); }
/** * 短时间显示Toast */ public static void showShort(Context context, int message) { if (null == toast) { toast = Toast.makeText(context, message, Toast.LENGTH_SHORT); // toast.setGravity(Gravity.CENTER, 0, 0); } else { toast.setText(message); } toast.show(); }
/** * 长时间显示Toast */ public static void showLong(Context context, CharSequence message) { if (null == toast) { toast = Toast.makeText(context, message, Toast.LENGTH_LONG); // toast.setGravity(Gravity.CENTER, 0, 0); } else { toast.setText(message); } toast.show(); }
/** * 自定义显示Toast时间 */ public static void show(Context context, CharSequence message, int duration) { if (null == toast) { toast = Toast.makeText(context, message, duration); // toast.setGravity(Gravity.CENTER, 0, 0); } else { toast.setText(message); } toast.show(); }
/** * 长时间显示Toast */ public static void showLong(Context context, int message) { if (null == toast) { toast = Toast.makeText(context, message, Toast.LENGTH_LONG); // toast.setGravity(Gravity.CENTER, 0, 0); } else { toast.setText(message); } toast.show(); }
/** * 自定义显示Toast时间 */ public static void show(Context context, int message, int duration) { if (null == toast) { toast = Toast.makeText(context, message, duration); // toast.setGravity(Gravity.CENTER, 0, 0); } else { toast.setText(message); } toast.show(); }
public static void show(CharSequence text, int duration) { text = TextUtils.isEmpty(text == null ? "" : text.toString()) ? "请检查您的网络!" : text; if (mToast == null) { mToast = Toast.makeText(context, text, duration); } else { mToast.setText(text); } mToast.show(); }
public static void showToast(String msg, int duration) { if (mToast == null) { mToast = Toast.makeText(getContext(), "", duration); } mToast.setText(msg); mToast.show(); }
@Override public void run() { if (mToast == null) { mToast = Toast.makeText(getContext(), "", Toast.LENGTH_SHORT); } mToast.setText(msg); mToast.show(); } });
public void randomPage(View view) { mDataList.clear(); int total = new Random().nextInt(CHANNELS.length); for (int i = 0; i <= total; i++) { mDataList.add(CHANNELS[i]); } mCommonNavigator.notifyDataSetChanged(); // must call firstly mExamplePagerAdapter.notifyDataSetChanged(); mToast.setText("" + mDataList.size() + " page"); mToast.show(); } }
protected void showToast(String desc){ if (mToast == null){ mToast = Toast.makeText(this.getApplicationContext(),desc,Toast.LENGTH_SHORT); }else{ mToast.setText(desc); } mToast.show(); } }
private Toast mToastText; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Create the object once. mToastText = Toast.makeText(this, "", Toast.LENGTH_SHORT); } private void displayText(final String message) { mToastText.cancel(); mToastText.setText(message); mToastText.show(); }
private static Toast initToast(CharSequence message, int duration) { if (toast == null) { toast = Toast.makeText(BaseApplication.getAppContext(), message, duration); } else { toast.setText(message); toast.setDuration(duration); } return toast; }
@Override public void onClick(View view) { cacheConfig = (cacheConfig + 1) % 5; DocumentView.CacheConfig newCacheConfig = DocumentView.CacheConfig.getById(cacheConfig); cacheConfigToast.setText("Activated " + newCacheConfig.name()); cacheConfigToast.show(); documentView.setCacheConfig(newCacheConfig); documentView.destroyCache(); documentView.invalidate(); } });
@Test public void shouldSetTextWithIdCorrectly() throws Exception { Toast toast = Toast.makeText(context, "short toast", Toast.LENGTH_SHORT); toast.setText(R.string.hello); toast.show(); assertThat(ShadowToast.getLatestToast()).isSameAs(toast); assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo("Hello"); assertThat(ShadowToast.showedToast("Hello")).isTrue(); }
@Test public void shouldSetTextCorrectly() throws Exception { Toast toast = Toast.makeText(context, "short toast", Toast.LENGTH_SHORT); toast.setText("other toast"); toast.show(); assertThat(ShadowToast.getLatestToast()).isSameAs(toast); assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo("other toast"); assertThat(ShadowToast.showedToast("other toast")).isTrue(); }