当前位置: 首页>>代码示例>>Java>>正文


Java Toast.setDuration方法代码示例

本文整理汇总了Java中android.widget.Toast.setDuration方法的典型用法代码示例。如果您正苦于以下问题:Java Toast.setDuration方法的具体用法?Java Toast.setDuration怎么用?Java Toast.setDuration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.widget.Toast的用法示例。


在下文中一共展示了Toast.setDuration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createShort

import android.widget.Toast; //导入方法依赖的package包/类
public Toast createShort() {
    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_SHORT);
    tvMsg.setText(msg);
    return toast;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:ToastUtil.java

示例2: show

import android.widget.Toast; //导入方法依赖的package包/类
public static void show(Context context, int color, CharSequence string, int duration) {
	if(context == null) return;

	DisplayMetrics dm = context.getResources().getDisplayMetrics();
	float density = dm.density;
	Toast toast = new Toast(context);
	toast.setDuration(duration);
	toast.setGravity(Gravity.TOP, 0, (int) (48 * density));
	FrameLayout frame = new FrameLayout(context);
	frame.setPadding(0, 0, 0, 0);
	int width = dm.widthPixels;
	FrameLayout.LayoutParams params =
			new FrameLayout.LayoutParams(width, FrameLayout.LayoutParams.WRAP_CONTENT);
	TextView text = new TextView(context);
	text.setMinimumHeight((int) (28 * density));
	text.setGravity(Gravity.CENTER);
	text.setTextColor(Color.WHITE);
	text.setTextSize(14);
	frame.addView(text, params);
	toast.setView(frame);

	text.setBackgroundColor(color);
	text.setText(string);
	toast.show();
}
 
开发者ID:marven88cn,项目名称:SwipeCard-,代码行数:26,代码来源:AppToast.java

示例3: show

import android.widget.Toast; //导入方法依赖的package包/类
public void show() {
    final Toast toast = new Toast(context);
    final View toastLayout = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.poizi_toast_layout, null);

    ImageView imgToastIcon = (ImageView) toastLayout.findViewById(R.id.imgToastIcon);
    TextView tvToastText = (TextView) toastLayout.findViewById(R.id.tvToastText);
    LinearLayout llPoiziToastRoot = (LinearLayout) toastLayout.findViewById(R.id.llPoiziToastRoot);

    initLlPoiziToastRoot(llPoiziToastRoot);
    initToastText(tvToastText);
    initToastIcon(imgToastIcon);

    toast.setView(toastLayout);

    toast.setDuration(poiziToastOptionModel.getDuration());

    setGravity(toast);

    toast.show();
}
 
开发者ID:Poizi,项目名称:PoiziToast,代码行数:22,代码来源:Exhibitioner.java

示例4: showWhiteSnackBar

import android.widget.Toast; //导入方法依赖的package包/类
private void showWhiteSnackBar(int signed_in_message) {
    LayoutInflater inflater = getLayoutInflater();
    FirebaseAuth auth = FirebaseAuth.getInstance();
    String userId;
    View layout = inflater.inflate(R.layout.custom_toast_view,
            (ViewGroup) findViewById(R.id.custom_toast_container));
    TextView text = (TextView) layout.findViewById(R.id.text);
    if (null != auth.getCurrentUser()) {
        userId = auth.getCurrentUser().getDisplayName();
        String strMeatFormat = getResources().getString(R.string.welcome_format);
        String strMeatMsg = String.format(strMeatFormat, userId);
        text.setText(strMeatMsg);
    } else {
        text.setText(signed_in_message);
    }
    Toast toast = new Toast(getApplicationContext());
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();
}
 
开发者ID:vixir,项目名称:Perfect-Day,代码行数:21,代码来源:LoginActivity.java

示例5: onOkPressed

import android.widget.Toast; //导入方法依赖的package包/类
@OnClick(R.id.create_ok_button)
protected void onOkPressed() {
    if (!mDescriptionInput.isCharactersCountValid()) {
        View layout = getActivity().getLayoutInflater().inflate(R.layout.custom_toast_view,
                (ViewGroup) getActivity().findViewById(R.id.custom_toast_container));
        TextView text = (TextView) layout.findViewById(R.id.text);
        if (mDescriptionInput.getText().toString().trim().equals("")) {
            text.setText(R.string.empty_task);
        } else {
            text.setText(R.string.invalid_task);
        }
        Toast toast = new Toast(getActivity());
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setView(layout);
        toast.show();
        return;
    }
    if (getTargetRequestCode() == NEW_ITEM) {
        sendBackCreateResult();
    }
    if (getTargetRequestCode() == EDIT_ITEM) {
        sendBackEditResult();
    }
    dismiss();
}
 
开发者ID:vixir,项目名称:Perfect-Day,代码行数:26,代码来源:ItemPickerDialogFragment.java

示例6: showToastSavor

import android.widget.Toast; //导入方法依赖的package包/类
public static void showToastSavor(Context context, String msg) {
    if(context==null)
        return;
    TextView tv = new TextView(context);
    tv.setBackgroundColor(context.getResources().getColor(R.color.black));
    tv.setTextColor(context.getResources().getColor(R.color.white));
   // tv.setBackgroundResource(R.drawable.bg_toast);
    tv.setTextSize(18);
    int px = DensityUtil.dip2px(context,10);
    tv.setPadding(px,px,px,px);
    tv.setText(msg);
    Toast toast = new Toast(context);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.setView(tv);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.show();
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:18,代码来源:ShowMessage.java

示例7: showCustomToast

import android.widget.Toast; //导入方法依赖的package包/类
/** 显示自定义Toast提示(来自String) **/
protected void showCustomToast(String text) {
	View toastRoot = LayoutInflater.from(this).inflate(
			R.layout.common_toast, null);
	((HandyTextView) toastRoot.findViewById(R.id.toast_text)).setText(text);
	Toast toast = new Toast(this);
	toast.setGravity(Gravity.CENTER, 0, 0);
	toast.setDuration(Toast.LENGTH_SHORT);
	toast.setView(toastRoot);
	toast.show();
}
 
开发者ID:qizhenghao,项目名称:HiBangClient,代码行数:12,代码来源:RegisterInfoActivity.java

示例8: onBackPressed

import android.widget.Toast; //导入方法依赖的package包/类
@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else if (1 == mViewPager.getCurrentItem()) {
        mViewPager.setCurrentItem(0);
    } else {
        if (doubleBackToExitPressedOnce) {
            super.onBackPressed();
            return;
        }

        this.doubleBackToExitPressedOnce = true;
        Toast makeText = Toast.makeText(this, "再按一次退出", Toast.LENGTH_SHORT);
        makeText.setDuration(Toast.LENGTH_SHORT);
        makeText.show();

        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                doubleBackToExitPressedOnce = false;
            }
        }, 2000);
    }
}
 
开发者ID:Sayi,项目名称:RestClient,代码行数:28,代码来源:HomeActivity.java

示例9: make

import android.widget.Toast; //导入方法依赖的package包/类
/**
 * Make a themed toast with text, icon, toastBackground and the tint color.
 *
 * @param context The context to use. Usually your {@link android.app.Application}
 *                or {@link android.app.Activity} object.
 * @param text The text to show. Can be formatted text.
 * @param icon The toast icon to show.
 * @param tintColor The toast tint color based on the toastBackground. It will
 *                  automatically check for the contrast to provide best
 *                  visibility.
 * @param backgroundColor The toast toastBackground color.
 * @param duration How long to display the message. Either
 *                 {@link Toast#LENGTH_SHORT} or {@link Toast#LENGTH_LONG}.
 *
 * @return Toast with the supplied parameters. Use {@link Toast#show()}
 *         to display the toast.
 */
public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text,
                                  @Nullable Drawable icon, @ColorInt int tintColor,
                                  @ColorInt int backgroundColor, int duration) {
    final Toast toast = new Toast(context);

    final View toastLayout = LayoutInflater.from(context).inflate(
            R.layout.adt_layout_hint, new LinearLayout(context), false);

    final ImageView toastIcon = toastLayout.findViewById(R.id.adt_hint_icon);
    final TextView toastText = toastLayout.findViewById(R.id.adt_hint_text);

    tintColor = DynamicColorUtils.getContrastColor(tintColor, backgroundColor);

    if (icon != null && !disableIcon) {
        if (iconSize != ADT_DEFAULT_ICON_SIZE) {
            toastIcon.getLayoutParams().width = iconSize;
            toastIcon.getLayoutParams().height = iconSize;
            toastIcon.requestLayout();
        }
        toastIcon.setColorFilter(tintColor);
        toastIcon.setImageDrawable(icon);
    } else {
        toastIcon.setVisibility(View.GONE);
    }

    if (textTypeface != null) {
        toastText.setTypeface(textTypeface);
    }
    if (textSize != ADT_DEFAULT_TEXT_SIZE) {
        toastText.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
    }
    toastText.setTextColor(tintColor);
    toastText.setText(text);

    if (toastBackground != null) {
        DynamicDrawableUtils.setBackground(toastLayout,
                DynamicDrawableUtils.colorizeDrawable(toastBackground,
                        backgroundColor, PorterDuff.Mode.MULTIPLY));
    } else {
        DynamicDrawableUtils.setBackground(toastLayout,
                DynamicDrawableUtils.colorizeDrawable(
                        ContextCompat.getDrawable(context, R.drawable.adt_hint_frame),
                        backgroundColor, PorterDuff.Mode.MULTIPLY));
    }

    toast.setDuration(duration);
    toast.setView(toastLayout);

    return toast;
}
 
开发者ID:pranavpandey,项目名称:dynamic-toasts,代码行数:68,代码来源:DynamicHint.java

示例10: show

import android.widget.Toast; //导入方法依赖的package包/类
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();
}
 
开发者ID:ccfish86,项目名称:sctalk,代码行数:16,代码来源:SpeekerToast.java

示例11: showToastInternal

import android.widget.Toast; //导入方法依赖的package包/类
private static void showToastInternal(Context context, int resId, int duration) {
	Toast toast;
	if (sToastRef == null || sToastRef.get() == null) {
		toast = Toast.makeText(context, resId, duration);
		sToastRef = new WeakReference<>(toast);
	} else {
		toast = sToastRef.get();
		if (toast != null) {
			toast.setDuration(duration);
			toast.setText(resId);
		} else return;
	}
	toast.show();
}
 
开发者ID:JackWHLiu,项目名称:jackknife,代码行数:15,代码来源:ToastUtils.java

示例12: show

import android.widget.Toast; //导入方法依赖的package包/类
public void show() {
    initStyleableToast();
    styleableToast = new Toast(context);
    styleableToast.setDuration(length == Toast.LENGTH_LONG ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT);
    styleableToast.setView(rootLayout);
    styleableToast.show();
}
 
开发者ID:Muddz,项目名称:StyleableToast,代码行数:8,代码来源:StyleableToast.java

示例13: show

import android.widget.Toast; //导入方法依赖的package包/类
/**
 * 显示吐司
 *
 * @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();
}
 
开发者ID:Lingzh0ng,项目名称:BrotherWeather,代码行数:19,代码来源:ToastUtils.java

示例14: showShort

import android.widget.Toast; //导入方法依赖的package包/类
@UiThread
public static void showShort(Context context, String message) {
    Toast toast = getToast(context);
    if (toast != null) {
        toast.setText(message);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.show();
    }
}
 
开发者ID:jiajieshen,项目名称:AndroidDevSamples,代码行数:10,代码来源:ToastUtil.java

示例15: showWhiteSnackBar

import android.widget.Toast; //导入方法依赖的package包/类
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();
}
 
开发者ID:vixir,项目名称:Perfect-Day,代码行数:12,代码来源:Utils.java


注:本文中的android.widget.Toast.setDuration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。