AndroidToast提示封裝

進階的玄武發表於2015-10-13
版權宣告:本文為博主原創文章,轉載請標明出處。 https://blog.csdn.net/lyhhj/article/details/49105201

Android中經常用到Toast提示,專案中很多Toast提示,寫很長的一行,簡單的封裝一下,將Toast方法提出來,很方便使用:

/**
     * 提示字串
     * short Toast
     * @param context
     * @param text
     * by Hankkin at:2015-10-07 21:14:43
     */
    public static void showToast(Context context, String text) {
        Toast toast = Toast.makeText(context,text,Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER,0,0);
        toast.show();
    }
    /**
     * 提示字串
     * short Toast
     * @param context
     * @param text
     * by Hankkin at:2015-10-07 21:14:43
     */
    public static void showLToast(Context context, String text) {
        Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    /**
     * 提示根據ResId關聯字串
     * short Toast
     * @param context
     * @param resId
     * by Hankkin at:2015-10-07 21:14:43
     */
    public static void showToast(Context context, int resId) {
        Toast toast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    /**
     * 提示根據ResId關聯字串
     * 時常long	Toast
     * @param context
     * @param resId
     * by Hankkin at:2015-10-07 21:14:43
     */
    public static void showLToast(Context context, int resId) {
        Toast toast = Toast.makeText(context, resId, Toast.LENGTH_LONG);;
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.


相關文章