當前位置: 首頁>>代碼示例>>Java>>正文


Java Toast.setText方法代碼示例

本文整理匯總了Java中android.widget.Toast.setText方法的典型用法代碼示例。如果您正苦於以下問題:Java Toast.setText方法的具體用法?Java Toast.setText怎麽用?Java Toast.setText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.widget.Toast的用法示例。


在下文中一共展示了Toast.setText方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: showToast

import android.widget.Toast; //導入方法依賴的package包/類
/**
 * {@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();
}
 
開發者ID:didikee,項目名稱:CommonDependence,代碼行數:26,代碼來源:UIToast.java

示例2: showToast

import android.widget.Toast; //導入方法依賴的package包/類
/**
 * {@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();
}
 
開發者ID:didikee,項目名稱:CommonDependence,代碼行數:29,代碼來源:UIToast2.java

示例3: createAboutToast

import android.widget.Toast; //導入方法依賴的package包/類
/**
 * Display a Toast with information about the application.
 *
 * @param packageManager usually retrieved by getPackageManager()
 * @param packageName    usually retrieved by getPackageName()
 */
void createAboutToast(final PackageManager packageManager, final String packageName, final Toast toast, final Context mContext) {
    try {
        final PackageInfo pInfo = packageManager.getPackageInfo(packageName, 0);
        toast.setText(mContext.getString(R.string.toast_version) + " " + pInfo.versionName
                + mContext.getString(R.string.toast_createdBy));
        toast.show();
    } catch (NameNotFoundException e) {
        toast.setText(R.string.toast_errorVersion);
        toast.show();
    }
}
 
開發者ID:RyuzakiKK,項目名稱:NoteCrypt,代碼行數:18,代碼來源:AboutToast.java

示例4: toast

import android.widget.Toast; //導入方法依賴的package包/類
private static void toast(Context context, String msg, int duration) {
    if (TextUtils.isEmpty(msg)) return;
    Toast t = null;
    if (sToastRef == null || sToastRef.get() == null) {
        t = Toast.makeText(context, msg, duration);
        sToastRef = new WeakReference<Toast>(t);
    } else {
        t = sToastRef.get();
        t.setText(msg);
        t.setDuration(duration);
    }
    t.show();
}
 
開發者ID:Pingsh,項目名稱:Mix,代碼行數:14,代碼來源:UIUtils.java

示例5: doShowToast

import android.widget.Toast; //導入方法依賴的package包/類
private final void doShowToast(Context context, String toast, int length) {
    try {
        Toast t = getToast(context);
        t.setText(toast);
        t.setDuration(length);
        t.show();
    } catch (Exception e) {
        Toast.makeText(context, toast, length).show();
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:11,代碼來源:ToastHelper.java

示例6: showToastInternal

import android.widget.Toast; //導入方法依賴的package包/類
private static void showToastInternal(Context context, String text, int duration) {
	Toast toast;
	if (sToastRef == null || sToastRef.get() == null) {
		toast = Toast.makeText(context, text, duration);
		sToastRef = new WeakReference<>(toast);
	} else {
		toast = sToastRef.get();
		if (toast != null) {
			toast.setDuration(duration);
			toast.setText(text);
		} else return;
	}
	toast.show();
}
 
開發者ID:JackWHLiu,項目名稱:jackknife,代碼行數:15,代碼來源:ToastUtils.java

示例7: intentOpenable

import android.widget.Toast; //導入方法依賴的package包/類
private boolean intentOpenable(Intent intent){
        if(getPackageManager().resolveActivity(intent,0) == null){
            Toast toast = new Toast(fromContext);
//            View v = LayoutInflater.from(fromContext).inflate(R.layout.toast_large,null);
//            ((TextView)v.findViewById(R.id.component_name)).setText(component);
//            toast.setView(v);
            toast.setText(component);
            toast.setDuration(Toast.LENGTH_LONG);
            toast.show();
            return false;
        }

        return true;
    }
 
開發者ID:daawa,項目名稱:auto-nav,代碼行數:15,代碼來源:BaseIntent.java

示例8: 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

示例9: showLong

import android.widget.Toast; //導入方法依賴的package包/類
@UiThread
public static void showLong(Context context, String message) {
    Toast toast = getToast(context);
    if (toast != null) {
        toast.setText(message);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.show();
    }
}
 
開發者ID:jiajieshen,項目名稱:AndroidDevSamples,代碼行數:10,代碼來源:ToastUtil.java

示例10: showToast

import android.widget.Toast; //導入方法依賴的package包/類
public static void showToast(Activity a, int resid) {
    Toast mToast = Toast.makeText(a, "", Toast.LENGTH_SHORT);
    mToast.setText(resid);
    mToast.show();
}
 
開發者ID:89luca89,項目名稱:ThunderMusic,代碼行數:6,代碼來源:InterfaceUtils.java


注:本文中的android.widget.Toast.setText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。