android.widget.Toast#setMargin ( )源码实例Demo

下面列出了android.widget.Toast#setMargin ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ToastUtils   文件: ToastUtils.java
/**
 * 设置当前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);
    }
}
 
源代码2 项目: YCDialog   文件: ToastUtils.java
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;
}
 
源代码3 项目: Pasta-Music   文件: Pasta.java
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();
}
 
源代码4 项目: Autoinstall   文件: TamicWindowManager.java
/**
 * 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;
}
 
源代码5 项目: Pasta-for-Spotify   文件: Pasta.java
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();
}