码迷,mamicode.com
首页 > 移动开发 > 详细

Android Toast封装

时间:2015-08-12 01:11:12      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

 

 

 

 

package com.whoop.mobile.trace.util;

import android.content.Context;
import android.content.res.Resources;
import android.view.Gravity;
import android.widget.Toast;

public class ToastUtil {
    private Context mContext;
    private Resources mResources;

    private ToastUtil() {
        super();
    }
    
    private ToastUtil(Context context){
        this.mContext = context;
        this.mResources = context.getResources();
    }
    
    public void showShortToast(String msg) {  
        showToast(mContext, msg, Toast.LENGTH_SHORT);  
    }  
  
    public void showShortToast(int strRes) {
        showShortToast(mResources.getString(strRes));
    }  
  
    public void showLongToast(String msg) {
        showToast(mContext, msg, Toast.LENGTH_LONG);  
    } 
    
    public void showLongToast(int strRes) {  
        showLongToast(mResources.getString(strRes));
    }  
  
    public void showToast(Context context, String msg, int duration){ 
        showToast(context, msg, duration,Gravity.CENTER); 
    }
    public void showToast(Context context, String msg, int duration,int gravity){ 
        Toast toast = Toast.makeText(context, msg, duration);
        toast.setGravity(gravity, 0, 0);
        toast.show();
    }
}

 

Android Toast封装

标签:

原文地址:http://www.cnblogs.com/exmyth/p/4722819.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!