本文整理匯總了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();
}