本文整理汇总了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();
}
示例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();
}
示例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();
}
}
示例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();
}
示例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();
}
}
示例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();
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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();
}