Java Code Examples for android.widget.Toast.setView()

The following are Jave code examples for showing how to use setView() of the android.widget.Toast class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ButterToast   File: ButterToast.java   View Source Code Vote up 6 votes
public static Toast custom(@NonNull Context context, CharSequence text, @Nullable Drawable icon,
                           @ColorInt int backgroundColor, int duration, @DrawableRes int resid,
                           @Nullable Typeface tp, float cornerRadius,
                           @ColorInt int textColor, float textSize) {
    Toast toast = new Toast(context);

    View layout = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.toast_layout, null);
    LinearLayout ll = (LinearLayout) layout.findViewById(R.id.base_layout);
    ll.setBackgroundResource(resid);
    GradientDrawable gd = (GradientDrawable) ll.getBackground().getCurrent();
    gd.setColor(backgroundColor);
    gd.setCornerRadius(cornerRadius);
    TextView tv_message = (TextView) layout.findViewById(R.id.toast_text);
    tv_message.setTextSize(textSize);
    tv_message.setTypeface(tp == null ? DEFAULT_TYPEFACE : tp);
    tv_message.setTextColor(textColor);
    ImageView iv_toast_image = (ImageView) layout.findViewById(R.id.toast_image);
    if (icon != null) {
        iv_toast_image.setImageDrawable(icon);
    }
    tv_message.setText(text);
    toast.setView(layout);
    toast.setDuration(duration);
    return toast;
}
 
Example 2
Project: RFID-Attendance   File: MainActivity.java   View Source Code Vote up 6 votes
/**
 * Display a checkmark toast to notify the user of a successful scan
 */
private void showCheckmarkToast(){
    // Inflate the toast layout
    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast_checkmark,
            (ViewGroup) findViewById(R.id.toast_layout_root));
    TextView text = (TextView) layout.findViewById(R.id.toast_text);
    text.setText(R.string.scan_successful);

    // Create the toast
    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();
}
 
Example 3
Project: CommonDependence   File: UIToast2.java   View Source Code Vote up 6 votes
/**
 * {@link layout/transient_notification.xml}
 * @param content content to show
 * @param longTime short or long
 * @param context context
 * @param textColor toast text color
 * @param toastBackgroundColor toast background color
 */
public static void showToast(@NonNull Context context, String content, boolean longTime, @ColorInt
        int textColor,@ColorInt int toastBackgroundColor) {
    int type = longTime ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
    Toast toast = Toast.makeText(context, content, type);
    ViewGroup toastView = (ViewGroup) LayoutInflater.from(context).inflate(R.layout
            .layout_toast, null, false);
    if (toastBackgroundColor != 0) {
        toastView.setBackgroundDrawable(getToastBackground(context, toastBackgroundColor));
    }
    TextView textView = (TextView) toastView.findViewById(android.R.id.message);
    // 内部已经作非空判断了
    if (textColor!=0){
        textView.setTextColor(textColor);
    }
    Typeface typeface = Typeface.create("sans-serif-condensed", Typeface.NORMAL);
    textView.setTypeface(typeface);
    toast.setView(toastView);
    toast.setText(content);
    toast.show();
}
 
Example 4
Project: androidtools   File: ToastUtils.java   View Source Code Vote up 6 votes
public static void showCenterToast(Context context, String title, @DrawableRes int drawableId, int duration) {
    Toast toast = makeText(context.getApplicationContext(), title, duration);
    toast.setGravity(Gravity.CENTER, 0, 0);
    View view = LayoutInflater.from(context).inflate(R.layout.layout_center_toast, null);
    LinearLayout rlContent = (LinearLayout) view.findViewById(R.id.rl_content);
    TextView content = (TextView) view.findViewById(R.id.tv_content);
    ImageView alertIcon = (ImageView) view.findViewById(R.id.iv_icon);
    if (drawableId != 0) {
        alertIcon.setVisibility(View.VISIBLE);
        alertIcon.setImageResource(drawableId);
    } else {
        alertIcon.setVisibility(View.GONE);
    }
    if (!TextUtils.isEmpty(title)) {
        content.setText(title);
    }
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    int screenWidth = wm.getDefaultDisplay().getWidth();
    int width = (int) (screenWidth / 2f);
    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) rlContent.getLayoutParams();
    lp.width = width;
    rlContent.setLayoutParams(lp);
    rlContent.requestLayout();
    toast.setView(view);
    toast.show();
}
 
Example 5
Project: CommonDependence   File: UIToast.java   View Source Code Vote up 6 votes
/**
 * {@link #tintDrawable(Drawable, ColorStateList)}
 * @param content content to show
 * @param longTime short or long
 * @param context context
 * @param textColor toast text color
 * @param toastBackgroundColor toast background color
 */
public static void showToast(@NonNull Context context, String content, boolean longTime,@ColorInt int toastBackgroundColor ,@ColorInt
        int textColor) {
    int type = longTime ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
    Toast toast = Toast.makeText(context, content, type);
    View toastView = toast.getView();
    TextView textView = (TextView) toastView.findViewById(android.R.id.message);
    if (toastBackgroundColor != 0){
        Drawable toastBackgroundDrawable = tintDrawable(toastView.getBackground(), ColorStateList.valueOf(toastBackgroundColor));
        toastView.setBackgroundDrawable(toastBackgroundDrawable);
    }
    if (textColor!=0){
        textView.setTextColor(textColor);
    }
    toast.setView(toastView);
    toast.setText(content);
    toast.show();
}
 
Example 6
Project: sctalk   File: SpeekerToast.java   View Source Code Vote up 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 7
Project: GitHub   File: ToastUtil.java   View Source Code Vote up 5 votes
public Toast create() {
    View contentView = View.inflate(context, R.layout.dialog_toast, null);
    TextView tvMsg = (TextView) contentView.findViewById(R.id.tv_toast_msg);
    toast = new Toast(context);
    toast.setView(contentView);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    tvMsg.setText(msg);
    return toast;
}
 
Example 8
Project: 2048-TimeKiller   File: Game.java   View Source Code Vote up 5 votes
private void customDisplay(String msg) {
    Toast tt = new Toast(this);
    LayoutInflater inflator = this.getLayoutInflater();
    View vv = inflator.inflate(R.layout.custom_toast_layout, null);
    TextView cTv = (TextView) vv.findViewById(R.id.cTv);
    cTv.setText(msg);
    vv.requestLayout();
    tt.setView(vv);
    tt.setGravity(Gravity.CENTER, 0, 0);
    tt.show();
}
 
Example 9
Project: VanGogh   File: DisplayToast.java   View Source Code Vote up 5 votes
/**
 * 初始化,单列
 *
 * @param 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 = new Toast(context);
	toast.setView(view);
}
 
Example 10
Project: NotificationStyles   File: ToastCenter.java   View Source Code Vote up 5 votes
private Toast show (int duration) {
    Toast toast = Toast.makeText(mContext, mText, duration);
    toast.setGravity(mGravity, xOffset, yOffset);
    toast.setMargin(horizontalMargin, verticalMargin);
    if (mView != null) {
        toast.setView(mView);
    }
    toast.show();
    return toast;
}
 
Example 11
Project: androidtools   File: ToastUtils.java   View Source Code Vote up 5 votes
/**
 * Show alert toast view
 *
 * @param context    context
 * @param title      title
 * @param drawableId drawable Id
 * @param duration   duration
 */
public static void showAlertToast(Context context, String title, @DrawableRes int drawableId, int duration) {
    Toast toast = makeText(context.getApplicationContext(), title, duration);
    toast.setGravity(Gravity.CENTER, 0, 0);//the setting position of
    View view = LayoutInflater.from(context).inflate(R.layout.layout_alert_toast, null);
    LinearLayout llContent = (LinearLayout) view.findViewById(R.id.ll_content);
    ImageView alertIcon = (ImageView) view.findViewById(R.id.iv_alert_icon);
    TextView alertTitle = (TextView) view.findViewById(R.id.tv_alert_title);
    if (drawableId != 0) {
        alertIcon.setVisibility(View.VISIBLE);
        alertIcon.setImageResource(drawableId);
    } else {
        alertIcon.setVisibility(View.GONE);
    }
    if (!TextUtils.isEmpty(title)) {
        alertTitle.setText(title);
    }
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    int screenWidth = wm.getDefaultDisplay().getWidth();
    int width = (int) (screenWidth / 1.5f);
    CardView.LayoutParams lp = (CardView.LayoutParams) llContent.getLayoutParams();
    lp.width = width;
    llContent.setLayoutParams(lp);
    llContent.requestLayout();
    toast.setView(view);//Set appearance
    toast.show();
}
 
Example 12
Project: BrotherWeather   File: ToastUtils.java   View Source Code Vote up 5 votes
/**
 * 显示吐司
 *
 * @param text     文本
 * @param duration 显示时长
 */
private static void show(CharSequence text, int duration) {
    cancel();
    if (customView != null) {
        sToast = new Toast(App.app);
        sToast.setView(customView);
        sToast.setDuration(duration);
    } else {
        sToast = Toast.makeText(App.app, text, duration);
    }
    sToast.setGravity(gravity, xOffset, yOffset);
    sToast.show();
}
 
Example 13
Project: Perfect-Day   File: Utils.java   View Source Code Vote up 5 votes
public static void showWhiteSnackBar(int signed_in_message, AppCompatActivity compatActivity) {
    LayoutInflater inflater = compatActivity.getLayoutInflater();
    View layout = inflater.inflate(R.layout.custom_toast_view,
            (ViewGroup) compatActivity.findViewById(R.id.custom_toast_container));
    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText(signed_in_message);
    Toast toast = new Toast(compatActivity);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();
}
 
Example 14
Project: Phoenix-for-VK   File: Utils.java   View Source Code Vote up 5 votes
public static void showRedTopToast(@NonNull Activity activity, String text) {
    View view = View.inflate(activity, R.layout.toast_error, null);
    ((TextView) view.findViewById(R.id.text)).setText(text);

    Toast toast = Toast.makeText(activity, text, Toast.LENGTH_SHORT);
    toast.setView(view);
    toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.TOP, 0, 0);
    toast.show();
}
 
Example 15
Project: letv   File: ToastUtils.java   View Source Code Vote up 5 votes
public static void show4dToast(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(48, 0, 100);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    toast.show();
}
 
Example 16
Project: SuperToast   File: SuperToast.java   View Source Code Vote up 5 votes
private void initData() {
    mCardView.setRadius(SuperToastUtils.dip2px(mContext, 20));
    mCardView.setCardElevation(2);
    mCardView.setCardBackgroundColor(SuperToastUtils.NORMAL_COLOR);
    mTextView.setTextColor(SuperToastUtils.DEFAULT_TEXT_COLOR);

    mDuration = Toast.LENGTH_SHORT;
    isOutDuration = false;
    isSetRadis = false;

    mToast = new Toast(mContext);
    mToast.setView(mParentView);
}
 
Example 17
Project: FancyToast-Android   File: FancyToast.java   View Source Code Vote up 5 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);
    if(type==1)
    { linearLayout.setBackgroundResource(R.drawable.success_shape);
      img.setImageResource(R.drawable.ic_check_black_24dp);
    }
    else if (type==2)
    { linearLayout.setBackgroundResource(R.drawable.warning_shape);
      img.setImageResource(R.drawable.ic_pan_tool_black_24dp);
    }
    else if (type==3)
    { linearLayout.setBackgroundResource(R.drawable.error_shape);
      img.setImageResource(R.drawable.ic_clear_black_24dp);
    }
    else if (type==4)
    { linearLayout.setBackgroundResource(R.drawable.info_shape);
      img.setImageResource(R.drawable.ic_info_outline_black_24dp);
    }
    else if (type==5)
    { linearLayout.setBackgroundResource(R.drawable.default_shape);
      img.setVisibility(View.GONE);
    }
    else if (type==6)
    { linearLayout.setBackgroundResource(R.drawable.confusing_shape);
      img.setImageResource(R.drawable.ic_refresh_black_24dp);
    }
    toast.setView(layout);
    return toast;
}
 
Example 18
Project: Toasty   File: Toasty.java   View Source Code Vote up 5 votes
@SuppressLint("ShowToast")
@CheckResult
public static Toast custom(@NonNull Context context, @NonNull CharSequence message, Drawable icon,
                           @ColorInt int tintColor, int duration,
                           boolean withIcon, boolean shouldTint) {
    final Toast currentToast = Toast.makeText(context, null, duration);
    final View toastLayout = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.toast_layout, null);
    final ImageView toastIcon = toastLayout.findViewById(R.id.toast_icon);
    final TextView toastTextView = toastLayout.findViewById(R.id.toast_text);
    Drawable drawableFrame;

    if (shouldTint)
        drawableFrame = ToastyUtils.tint9PatchDrawableFrame(context, tintColor);
    else
        drawableFrame = ToastyUtils.getDrawable(context, R.drawable.toast_frame);
    ToastyUtils.setBackground(toastLayout, drawableFrame);

    if (withIcon) {
        if (icon == null)
            throw new IllegalArgumentException("Avoid passing 'icon' as null if 'withIcon' is set to true");
        if (tintIcon)
            icon = ToastyUtils.tintIcon(icon, DEFAULT_TEXT_COLOR);
        ToastyUtils.setBackground(toastIcon, icon);
    } else {
        toastIcon.setVisibility(View.GONE);
    }

    toastTextView.setText(message);
    toastTextView.setTextColor(DEFAULT_TEXT_COLOR);
    toastTextView.setTypeface(currentTypeface);
    toastTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);

    currentToast.setView(toastLayout);
    return currentToast;
}
 
Example 19
Project: mongol-library   File: MongolToast.java   View Source Code Vote up 4 votes
public void show() {
    Toast mongolToast = new Toast(context);
    mongolToast.setDuration(duration);
    mongolToast.setView(getLayout());
    mongolToast.show();
}
 
Example 20
Project: JkShoppingCart   File: ToastUtils.java   View Source Code Vote up 4 votes
public static void show(Context context, View view) {
	Toast toast = new Toast(context);
	toast.setGravity(Gravity.CENTER, 0, 0);
	toast.setView(view);
	toast.show();
}