@Override public IToast setMargin(float horizontalMargin, float verticalMargin) { mToast.setMargin(horizontalMargin, verticalMargin); return this; }
@Override public IToast setMargin(float horizontalMargin, float verticalMargin) { mToast.setMargin(horizontalMargin, verticalMargin); return this; }
@Override public IToast setMargin(float horizontalMargin, float verticalMargin) { mToast.setMargin(horizontalMargin, verticalMargin); return this; }
@Override public IToast setMargin(float horizontalMargin, float verticalMargin) { mToast.setMargin(horizontalMargin, verticalMargin); return this; }
if (url.startsWith("share://")) { Uri requestUrl = Uri.parse(url); String pContent = requestUrl.toString().split("share://")[1]; // pContent = firstWord <br /> secondWord <br /> ThirdWord Toast toast=Toast.makeText(getApplicationContext(),pContent, Toast.LENGTH_LONG); toast.setMargin(50,50); toast.show(); StringBuilder sb = new StringBuilder(); String [] parts = pContent.split("<br />"); for (int i = 0; i < parts.length; i++) { String part = parts[i]; sb.append(part); sb.append('\n'); } Intent share = new Intent(Intent.ACTION_SEND); share.setAction(Intent.ACTION_SEND); share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); share.putExtra(android.content.Intent.EXTRA_TEXT, (Serializable) sb); share.setType("text/plain"); startActivity(Intent.createChooser(share, "Share On")); return true;
if (url.startsWith("share://")) { Intent share = new Intent(Intent.ACTION_SEND); Uri requestUrl = Uri.parse(url); String pContent = requestUrl.toString().split("share://")[1]; String pasteData = pContent+""; share.setAction(Intent.ACTION_SEND); share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Toast toast=Toast.makeText(getApplicationContext(),pasteData, Toast.LENGTH_LONG); toast.setMargin(50,50); toast.show(); StringBuilder sb = new StringBuilder(); String [] parts = pasteData.split("<br />"); for (int i = 0; i < parts.length; i++) { String part = parts[i]; sb.append(part); sb.append('\n'); } share.putExtra(android.content.Intent.EXTRA_TEXT, (Serializable) sb); //share.setType("message/rfc822"); //share.setType("text/plain"); share.setType("*/*"); startActivity(Intent.createChooser(share, "Share On")); return true;
@Override public void run() { if (null == ctx) { return; } if (toast == null) toast = new Toast(ctx); View view = LayoutInflater.from(ctx).inflate(R.layout.dialog_toast, null); TextView message = (TextView) view.findViewById(R.id.tv_msg); message.setText(msg); toast.setGravity(Gravity.BOTTOM, Gravity.CENTER_HORIZONTAL, Gravity.BOTTOM); toast.setMargin(0, 0.1f); toast.setDuration(duration); toast.setView(view); toast.show(); } });
@Override public void run() { if (null == context) { return; } View view = LayoutInflater.from(ctx).inflate( R.layout.dialog_toast, null); TextView message = (TextView) view.findViewById(R.id.tv_msg); message.setText(resId); if (toast == null) toast = new Toast(ctx); toast.setGravity(Gravity.BOTTOM, Gravity.CENTER_HORIZONTAL, Gravity.BOTTOM); toast.setMargin(0, 0.1f); toast.setDuration(duration); toast.setView(view); toast.show(); } });
/** * 弹出自定义Toast * * @param context * @param msg */ public static void showToast(Context context, String msg) { try { Toast toast = new Toast(context); View view = View.inflate(context, R.layout.view_toast, null); TextView textView = (TextView) view.findViewById(R.id.tv_toast); textView.setText(msg); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(view); toast.setGravity(Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0); toast.setMargin(0, 0); toast.show(); } catch (Exception e) { //Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference e.printStackTrace(); } } }
/** * 带有图片的Toast * * @param mContext 上下文 * @param picID 左边图标的id * @param title 标题 */ public static void showPhotoToast(Context mContext, int picID, String title) { try { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.view_toast, null); Toast toast = new Toast(mContext); TextView textView = (TextView) view.findViewById(R.id.tv_toast); textView.setText(title); ImageView ivToast = (ImageView) view.findViewById(R.id.ivToast); ivToast.setBackground(mContext.getResources().getDrawable(picID)); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(view); toast.setGravity(Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0); toast.setMargin(0, 0); toast.show(); } catch (Exception e) { //Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference e.printStackTrace(); } }
@SuppressLint("InflateParams") private static void showToast(Context context, String text, int type, long time) { if (time <= 0) time = 1500; if (time >= 3500) time = 3500; final Toast toast = new Toast(context); View view = LayoutInflater.from(context).inflate(R.layout.toast_view, null, false); if (type == TYPE_SUCCESS) { ViewSetting.setImageResource(view, R.id.toast_image, R.drawable.success); view.setBackgroundColor(Color.parseColor("#b4eeb4")); } else if (type == TYPE_INFO) { ViewSetting.setImageResource(view, R.id.toast_image, R.drawable.info); view.setBackgroundColor(Color.parseColor("#87ceeb")); } else if (type == TYPE_ERROR) { ViewSetting.setImageResource(view, R.id.toast_image, R.drawable.error); view.setBackgroundColor(Color.parseColor("#ffa54f")); } ViewSetting.setTextView(view, R.id.toast_text, text); toast.setDuration(Toast.LENGTH_LONG); toast.setView(view); toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 0); toast.setMargin(0, 0.35f); toast.show(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { toast.cancel(); } }, time); }