当前位置: 首页>>代码示例>>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;未经允许,请勿转载。