當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。