1.最原始的Toast显示封装
public static void showToast(Context context,String msg){
Toast.makeText(context , msg , Toast.LENGTH_SHORT).show();
}
2.设置显示Toast的位置 屏幕中间显示
public static void showToast(Context context,String msg){
Toast toast = Toast.makeText(context , msg , Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER , 0 , 0);
toast.show();
}
3.显示带图片的Toast
public static void showToast(Context context,String msg){
Toast toast = Toast.makeText(context , msg , Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER , 0 , 0);
LinearLayout toastView = (LinearLayout)toast.getView();
ImageView image = new ImageView(context);
image.setImageResource(R.drawable.icon);
toastView.add(image,0);
toast.show();
}
4.
public static void showToast(Context context,int stringId){
String msg = context.getResources().getString(stringId);
showToast(context , msg);
}