Java Code Examples for android.widget.Toast#setMargin()
The following examples show how to use
android.widget.Toast#setMargin() .
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: ToastUtils.java From ToastUtils with Apache License 2.0 | 5 votes |
/** * 设置当前Toast对象 */ public static void setToast(Toast toast) { checkNullPointer(toast); if (sToast != null && toast.getView() == null) { // 移花接木 toast.setView(sToast.getView()); toast.setGravity(sToast.getGravity(), sToast.getXOffset(), sToast.getYOffset()); toast.setMargin(sToast.getHorizontalMargin(), sToast.getVerticalMargin()); } sToast = toast; if (sStrategy != null) { sStrategy.bind(sToast); } }
Example 2
Source File: ToastUtils.java From YCDialog with Apache License 2.0 | 5 votes |
public Toast build() { if (!DialogUtils.checkNull(mToast)) { mToast.get().cancel(); } Toast toast = new Toast(context); if (isFill) { toast.setGravity(gravity | Gravity.FILL_HORIZONTAL, 0, yOffset); } else { toast.setGravity(gravity, 0, yOffset); } toast.setDuration(duration); toast.setMargin(0, 0); if(layout==0){ CardView rootView = (CardView) LayoutInflater.from(context).inflate(R.layout.view_toast_custom, null); TextView textView = rootView.findViewById(R.id.toastTextView); TextView descTv = rootView.findViewById(R.id.desc); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //rootView.setElevation(elevation); rootView.setCardElevation(elevation); } rootView.setRadius(radius); rootView.setCardBackgroundColor(backgroundColor); //rootView.setBackgroundColor(backgroundColor); textView.setTextColor(textColor); textView.setText(title); if(TextUtils.isEmpty(desc)){ descTv.setVisibility(View.GONE); }else{ descTv.setText(desc); descTv.setVisibility(View.VISIBLE); } toast.setView(rootView); }else { View view = LayoutInflater.from(context).inflate(layout, null); toast.setView(view); } mToast = new SoftReference<>(toast); return toast; }
Example 3
Source File: Pasta.java From Pasta-Music with Apache License 2.0 | 5 votes |
public void showToast(String message) { Toast toast = new Toast(this); View snackbar = LayoutInflater.from(this).inflate(R.layout.snackbar_layout, null); ((TextView) snackbar.findViewById(R.id.message)).setText(message); ViewCompat.setElevation(snackbar, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics())); toast.setView(snackbar); toast.setDuration(Toast.LENGTH_LONG); toast.setMargin(0, 0); toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0); toast.show(); }
Example 4
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 5
Source File: Pasta.java From Pasta-for-Spotify with Apache License 2.0 | 5 votes |
public void showToast(String message) { Toast toast = new Toast(this); View snackbar = LayoutInflater.from(this).inflate(R.layout.snackbar_layout, null); ((TextView) snackbar.findViewById(R.id.message)).setText(message); ViewCompat.setElevation(snackbar, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics())); toast.setView(snackbar); toast.setDuration(Toast.LENGTH_LONG); toast.setMargin(0, 0); toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0); toast.show(); }