Java Code Examples for android.widget.Toast#setText()
The following examples show how to use
android.widget.Toast#setText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomShadowToast.java From SnackbarBuilder with Apache License 2.0 | 6 votes |
/** * Implementation of makeText that actually shows the message. */ @Implementation @SuppressLint("ShowToast") public static Toast makeText(Context context, CharSequence text, int duration) { LinearLayout layout = new LinearLayout(context); layout.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); TextView messageView = new TextView(context); layout.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); messageView.setId(android.R.id.message); layout.addView(messageView); Toast toast = new Toast(context); toast.setView(layout); toast.setDuration(duration); toast.setText(text); return toast; }
Example 2
Source File: ToastUtils.java From QuickerAndroid with GNU General Public License v3.0 | 5 votes |
private static void show(Context context, String message, int duration) { Toast toast = getToast(context); if (toast != null) { toast.setText(message); toast.setDuration(duration); toast.show(); } }
Example 3
Source File: ToastUtils.java From QuickerAndroid with GNU General Public License v3.0 | 5 votes |
private static void show(Context context, @StringRes int messageRes, int duration) { Toast toast = getToast(context); if (toast != null) { toast.setText(messageRes); toast.setDuration(duration); toast.show(); } }
Example 4
Source File: ToastUtils.java From YCDialog with Apache License 2.0 | 5 votes |
@SuppressLint("ShowToast") public static void showToast(String content) { DialogUtils.checkMainThread(); checkContext(); if (!DialogUtils.checkNull(mToast)) { mToast.get().cancel(); } Toast toast = Toast.makeText(mApp, "", Toast.LENGTH_SHORT); toast.setText(content); toast.show(); mToast = new SoftReference<>(toast); }
Example 5
Source File: AboutToast.java From NoteCrypt with GNU General Public License v3.0 | 5 votes |
/** * 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(); } }
Example 6
Source File: ToastHelper.java From letv with Apache License 2.0 | 5 votes |
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(); } }
Example 7
Source File: TextToast.java From rebootmenu with GNU General Public License v3.0 | 5 votes |
/** * toast兼容适配 * * @param context {@link Context} * @param text 文本信息 * @param isLong 是否是持续时间较长的toast * @param isCenter 是否显示在中心位置 */ private static void toastCompat(Context context, CharSequence text, boolean isLong, boolean isCenter) { boolean isMI = SpecialSupport.isMIUI(); //MIUI的Toast在文本前面添加应用名称很不合理,因为Toast显示时间有限,需要尽快让用户注意最重要的内容 Toast toast = Toast.makeText(context.getApplicationContext(), isMI ? null : text, isLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT); if (isMI) toast.setText(text); if (isCenter) toast.setGravity(Gravity.CENTER, 0, 0); fixBadTokenException(context, toast); toast.show(); }
Example 8
Source File: ApolloUtils.java From mobile-manager-tool with MIT License | 5 votes |
/** * @param message */ public static void showToast(int message, Toast mToast, Context context) { if (mToast == null) { mToast = Toast.makeText(context, "", Toast.LENGTH_SHORT); } mToast.setText(context.getString(message)); mToast.show(); }
Example 9
Source File: TamicWindowManager.java From Autoinstall with Apache License 2.0 | 5 votes |
/** * BdToastCustom constucts * @param context context * @param text text * @param time time */ private TamicWindowManager(Context context, String text, double time){ wdm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); timer = new Timer(); // mView = LayoutInflater.from(context).inflate(R.layout.activity_loading, null); mView = new TamcWaitingView(context); Toast toast = new Toast(context); toast.setDuration(Toast.LENGTH_SHORT); toast.setMargin(0, 0); toast.setGravity(Gravity.CENTER, 0, 0); toast.setView(mView); toast.setText(text); params = new WindowManager.LayoutParams(); params.height = WindowManager.LayoutParams.MATCH_PARENT; params.width = WindowManager.LayoutParams.MATCH_PARENT; params.format = PixelFormat.TRANSLUCENT; params.windowAnimations = toast.getView().getAnimation().INFINITE; params.type = WindowManager.LayoutParams.TYPE_TOAST; params.setTitle("Toast"); params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER; params.y = -30; this.time = time; }
Example 10
Source File: ToastUtils.java From AndroidUtilCode with Apache License 2.0 | 4 votes |
private static Toast makeNormalToast(Context context, CharSequence text, int duration) { @SuppressLint("ShowToast") Toast toast = Toast.makeText(context, "", duration); toast.setText(text); return toast; }
Example 11
Source File: ToastUtil.java From AndroidLinkup with GNU General Public License v2.0 | 3 votes |
/** * 根据字符串获取toast * * @param ctx * 上下文 * @param msg * 字符串 * @return Toast对象 */ public static Toast getToast(Context ctx, String msg) { Toast mToast = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT); mToast.setText(msg); mToast.setGravity(Gravity.BOTTOM | Gravity.CENTER, 0, 20); mToast.setDuration(Toast.LENGTH_SHORT); return mToast; }