自定义Toast

1.

public class ShowToast 
{
	public static void show(Context context, String content)
	{
		View toastRoot = ((Activity) context).getLayoutInflater().inflate(R.layout.toast, null);
		Toast toast=new Toast(context.getApplicationContext());
		 toast.setView(toastRoot);
		TextView tv=(TextView)toastRoot.findViewById(R.id.my_toast);
		tv.setText(content);
		toast.setGravity(Gravity.NO_GRAVITY, 0, 100);
		toast.setDuration(Toast.LENGTH_LONG);
		toast.show();
	}
}

 

2.toast.xml




    
       

你可能感兴趣的:(ND实习小记之Android,移动开发)