Young87

当前位置:首页 >个人收藏

Toast自定义

public class CustomerToast extends Toast {
/**
 * Construct an empty Toast object.  You must call {@link #setView} before you
 * can call {@link #show}.
 *
 * @param context The context to use.  Usually your {@link Application}
 * or {@link Activity} object.
 */

private TextView contentTv;

public CustomerToast(Context context) {
    super(context);
    View view = LayoutInflater.from(context).inflate(R.layout.toast_ll, null);
    contentTv = view.findViewById(R.id.content_tv);
    setView(view);
}

public static CustomerToast makeToast(String content) {

    CustomerToast customerToast = new CustomerToast(MyApplication.getInstance());
    customerToast.setDuration(Toast.LENGTH_SHORT);
    customerToast.setGravity(Gravity.CENTER, 0, 0);
    customerToast.contentTv.setText(content);
    return customerToast;
}
}

除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog

上一篇: 通过css属性overflow设置元素出现滚动条

下一篇: docker容器常用操作

精华推荐