Java Code Examples for android.widget.Toast#setView()
The following examples show how to use
android.widget.Toast#setView() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatsActivity.java From NightWatch with GNU General Public License v3.0 | 6 votes |
private void showStartupInfo() { if (swipeInfoNotNeeded) { //show info only if user didn't swipe already. return; } TextView tv = new TextView(this); tv.setText("Swipe left/right to switch between reports!"); tv.setTextColor(Color.CYAN); tv.setTextSize(28); for (int i = 0; i < 2; i++) { //Show toast twice the "long" period Toast toast = new Toast(getApplicationContext()); toast.setView(tv); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); } }
Example 2
Source File: ImageActivity.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
private void b(String s1, int i1) { Toast toast = Toast.makeText(this, s1, 1); LinearLayout linearlayout = (LinearLayout)toast.getView(); ((TextView)linearlayout.getChildAt(0)).setPadding(8, 0, 0, 0); ImageView imageview = new ImageView(this); imageview.setLayoutParams(new android.widget.LinearLayout.LayoutParams(com.tencent.connect.avatar.c.a(this, 16F), com.tencent.connect.avatar.c.a(this, 16F))); if (i1 == 0) { imageview.setImageDrawable(b("com.tencent.plus.ic_success.png")); } else { imageview.setImageDrawable(b("com.tencent.plus.ic_error.png")); } linearlayout.addView(imageview, 0); linearlayout.setOrientation(0); linearlayout.setGravity(17); toast.setView(linearlayout); toast.setGravity(17, 0, 0); toast.show(); }
Example 3
Source File: CustomizedToast.java From AlipayPullRefresh with Apache License 2.0 | 6 votes |
/** * 一种自定义的Toast * * @param toastStr 字符串 */ public void showToast(Context context, String toastStr) { if (null != lastToast) { lastToast.cancel(); } // 初始化ToastView LayoutInflater inflater = LayoutInflater.from(context.getApplicationContext()); View toastView = inflater.inflate(R.layout.toast_layout, null); TextView toastTv = toastView.findViewById(R.id.toast_tv); toastTv.setText(toastStr); // 初始化Toast Toast toast = new Toast(context.getApplicationContext()); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(toastView); toast.setGravity(Gravity.BOTTOM, 0, Utils.dp2px(context.getApplicationContext(), 30)); toast.show(); lastToast = toast; }
Example 4
Source File: ToastUtil.java From WanAndroid with Apache License 2.0 | 5 votes |
@SuppressLint({"ResourceAsColor"}) public static void toastInCenter(Context context, String message) { @SuppressLint("InflateParams") View toastView = LayoutInflater.from(context).inflate(R.layout.toast_center, null); TextView textView = toastView.findViewById(R.id.tv_toast); textView.setText(message); Toast toast = new Toast(context); toast.setGravity(17, 0, 0); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(toastView); toast.show(); }
Example 5
Source File: CT.java From Android-CustomToast with GNU General Public License v3.0 | 5 votes |
public CT(Builder builder) { LayoutInflater inflater = (LayoutInflater) builder.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.custom_layout, null); TextView tv = layout.findViewById(R.id.cltv); tv.setText(builder.text); tv.setTextColor(builder.textCol); ImageView iv = layout.findViewById(R.id.cliv); iv.setImageResource(builder.imageRes); GradientDrawable shape = new GradientDrawable(); shape.setShape(builder.shape); shape.setCornerRadii(new float[]{ builder.radiusTopLeft, builder.radiusTopLeft, builder.radiusTopRight, builder.radiusTopRight, builder.radiusBottomRight, builder.radiusBottomRight, builder.radiusBottomLeft, builder.radiusBottomLeft }); shape.setColor(builder.backCol); shape.setStroke(builder.borderWidth, builder.borderCol); layout.setBackgroundDrawable(shape); Toast toast = new Toast(builder.context); toast.setView(layout); toast.setDuration(builder.toastDuration); toast.setGravity(builder.toastGravity,0,100); toast.show(); }
Example 6
Source File: ToastUtils.java From letv with Apache License 2.0 | 5 votes |
public static void showCentorTextToast(Context context, String text) { if (mToast != null) { mToast.cancel(); } View layout = LayoutInflater.from(context).inflate(R.layout.toast_center_text, (ViewGroup) ((Activity) context).findViewById(R.id.toast_layout_root)); ((TextView) layout.findViewById(R.id.text)).setText(text); Toast toast = new Toast(context); toast.setGravity(16, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); }
Example 7
Source File: SpeekerToast.java From sctalk with Apache License 2.0 | 5 votes |
public static void show(Context context, CharSequence text, int duration) { LayoutInflater inflater = ((Activity) context).getLayoutInflater(); View view = inflater.inflate(R.layout.tt_speeker_layout, null); TextView title = (TextView) view.findViewById(R.id.top_tip); title.setText(text); Toast toast = new Toast(context.getApplicationContext()); toast.setGravity( Gravity.FILL_HORIZONTAL | Gravity.TOP, 0, (int) context.getResources().getDimension( R.dimen.top_bar_default_height)); toast.setDuration(duration); toast.setView(view); toast.show(); }
Example 8
Source File: MainActivity.java From GifView with Apache License 2.0 | 5 votes |
public void showToast() { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.custom_toast, null); Toast toastLocal = new Toast(getApplicationContext()); toastLocal.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toastLocal.setDuration(Toast.LENGTH_LONG); toastLocal.setView(layout); toastLocal.show(); }
Example 9
Source File: ToastUtils.java From Android-UtilCode with Apache License 2.0 | 5 votes |
/** * 显示吐司 * * @param text 文本 * @param duration 显示时长 */ private static void show(CharSequence text, int duration) { cancel(); if (customView != null) { sToast = new Toast(Utils.getContext()); sToast.setView(customView); sToast.setDuration(duration); } else { sToast = Toast.makeText(Utils.getContext(), text, duration); } sToast.setGravity(gravity, xOffset, yOffset); sToast.show(); }
Example 10
Source File: DisplayToast.java From DownloadManager with Apache License 2.0 | 5 votes |
/** * 在应用Application中初始化 * * @param context 上下文用Context */ public void init(Context context) { View view = LayoutInflater.from(context).inflate(R.layout.view_toast, null); tvToast = (TextView) view.findViewById(R.id.tv_toast); //初始化Toast并把View设置给它 toast = new Toast(context); toast.setView(view); }
Example 11
Source File: BaseApplication.java From Cotable with Apache License 2.0 | 5 votes |
/** * Show the toast for the current application. * * @param message the message content * @param duration the duration * @param icon the icon resource * @param gravity the gravity of the toast */ public static void showToast(String message, int duration, int icon, int gravity) { if (message == null || message.equalsIgnoreCase("")) return; long time = System.currentTimeMillis(); if (!message.equalsIgnoreCase(lastToast) || Math.abs(time - lastToastTime) > 2000) { View view = LayoutInflater.from(context()).inflate( R.layout.view_toast, null); ((TextView) view.findViewById(R.id.tv_text)).setText(message); if (icon != 0) { ImageView mIcon = (ImageView) view.findViewById(R.id.iv_icon); mIcon.setImageResource(icon); mIcon.setVisibility(View.VISIBLE); } Toast toast = new Toast(context()); toast.setView(view); toast.setGravity(gravity, 0, TDevice.getActionBarHeight(context())); toast.setDuration(duration); toast.show(); lastToast = message; lastToastTime = System.currentTimeMillis(); } }
Example 12
Source File: Cue.java From Cue with Apache License 2.0 | 5 votes |
public void show() { if(context==null) return; // do nothing if context is now null (avoid NullPointerException) Toast toast = new Toast(context.getApplicationContext()); View view = LayoutInflater.from(context).inflate(R.layout.content_custom_toast, null, false); TextView custom_text = view.findViewById(R.id.custom_text); custom_text.setGravity(textGravity); custom_text.setText(message); custom_text.setTextSize(textSize); custom_text.setPadding(padding, padding, padding, padding); if (!fontFaceString.isEmpty()) { Typeface typeface = Typeface.createFromAsset(context.getAssets(), fontFaceString); custom_text.setTypeface(typeface); } getShape(type, custom_text); toast.setDuration(duration == Duration.LONG ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT); toast.setGravity(gravity, 0, 0); toast.setView(view); toast.show(); if(hideToast){ view.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { toast.cancel(); } }); } }
Example 13
Source File: MainActivity.java From Android-9-Development-Cookbook with MIT License | 5 votes |
public void showToast(View view) { LayoutInflater inflater = (LayoutInflater)this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.toast_custom, null); ((TextView)layout.findViewById(android.R.id.message)).setText("Custom Toast"); Toast toast = new Toast(this); toast.setGravity(Gravity.CENTER, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); }
Example 14
Source File: ToastHelper.java From mobikul-standalone-pos with MIT License | 5 votes |
public static void showToast(@NonNull Context context, @NonNull String msg, int duration, int icon) { if (!msg.isEmpty()) { CustomToastBinding customToastBinding = CustomToastBinding.inflate(LayoutInflater.from(context)); customToastBinding.setMessage(Html.fromHtml(msg).toString()); Toast toast = new Toast(context); toast.setGravity(Gravity.BOTTOM, 0, 150); toast.setView(customToastBinding.getRoot()); toast.setDuration(duration); toast.show(); } }
Example 15
Source File: ZidooRecorderTool.java From zidoorecorder with Apache License 2.0 | 5 votes |
public static void Toast_MSG(Context context, String msg) { Toast toa = new Toast(context); toa.setDuration(Toast.LENGTH_SHORT); View tView = LayoutInflater.from(context).inflate(R.layout.msg_toast, null); TextView tvmsg = (TextView) tView.findViewById(R.id.msg_toast_text); tvmsg.setText(msg); toa.setView(tView); toa.show(); }
Example 16
Source File: Example.java From codeexamples-android with Eclipse Public License 1.0 | 4 votes |
public void showMessage(View view) { Toast toast = new Toast(this); toast.setDuration(Toast.LENGTH_LONG); toast.setView(toastLayout); toast.show(); }
Example 17
Source File: CameraFragment.java From io2015-codelabs with Apache License 2.0 | 4 votes |
private void startVoiceTimer() { Log.d(TAG, "startVoiceTimer: "); final int countdown = getArguments().getInt(EXTRA_TIMER_DURATION_SECONDS); mTimerCountdownToast = new Toast(getActivity().getApplicationContext()); mTimerCountdownToast.setGravity(Gravity.CENTER, 0, 0); mTimerCountdownToast.setDuration(Toast.LENGTH_SHORT); LayoutInflater inflater = getActivity().getLayoutInflater(); View layout = inflater.inflate(R.layout.toast_timer, (ViewGroup) getActivity().findViewById(R.id.toast_layout_root)); mTimerCountdownToast.setView(layout); final TextView label = (TextView) layout.findViewById(R.id.countdown_text); Timer timer = new Timer("camera_timer"); timer.scheduleAtFixedRate(new TimerTask() { private int mCountdown = countdown; @Override public void run() { getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (mCountdown < 0) { Log.e(TAG, "Take photo: " + mCountdown); mTimerCountdownToast.cancel(); takePicture(); } else { Log.e(TAG, "Execute timer: " + mCountdown); label.setText(String.format("Photo in %d", mCountdown)); mTimerCountdownToast.show(); } } }); mCountdown--; if (mCountdown < 0) { cancel(); } } }, 1000, 1000); }
Example 18
Source File: FancyToast.java From FancyToast-Android with Apache License 2.0 | 4 votes |
public static Toast makeText(Context context, String message, int duration, int type, boolean androidIcon) { Toast toast = new Toast(context); toast.setDuration(duration); View layout = LayoutInflater.from(context).inflate(R.layout.fancytoast_layout, null, false); TextView l1 = (TextView) layout.findViewById(R.id.toast_text); LinearLayout linearLayout = (LinearLayout) layout.findViewById(R.id.toast_type); ImageView img = (ImageView) layout.findViewById(R.id.toast_icon); ImageView img1 = (ImageView) layout.findViewById(R.id.imageView4); l1.setText(message); if (androidIcon == true) img1.setVisibility(View.VISIBLE); else if (androidIcon == false) img1.setVisibility(View.GONE); switch (type) { case 1: linearLayout.setBackgroundResource(R.drawable.success_shape); img.setImageResource(R.drawable.ic_check_black_24dp); break; case 2: linearLayout.setBackgroundResource(R.drawable.warning_shape); img.setImageResource(R.drawable.ic_pan_tool_black_24dp); break; case 3: linearLayout.setBackgroundResource(R.drawable.error_shape); img.setImageResource(R.drawable.ic_clear_black_24dp); break; case 4: linearLayout.setBackgroundResource(R.drawable.info_shape); img.setImageResource(R.drawable.ic_info_outline_black_24dp); break; case 5: linearLayout.setBackgroundResource(R.drawable.default_shape); img.setVisibility(View.GONE); break; case 6: linearLayout.setBackgroundResource(R.drawable.confusing_shape); img.setImageResource(R.drawable.ic_refresh_black_24dp); break; } toast.setView(layout); return toast; }
Example 19
Source File: KcaCustomToast.java From kcanotify_h5-master with GNU General Public License v3.0 | 4 votes |
private void show(Toast toast, View v, int duration) { //toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(duration); toast.setView(v); toast.show(); }
Example 20
Source File: ToastUtils.java From HttpRequest with Apache License 2.0 | 3 votes |
/** * show toast * @author leibing * @createTime 2017/5/25 * @lastModify 2017/5/25 * @param context * @param view * @return */ public static void show(Context context, View view) { Toast toast = new Toast(context); toast.setGravity(Gravity.CENTER, 0, 0); toast.setView(view); toast.show(); }