自定义Toast弹出样式

//获取样式布局
View toastRoot = LayoutInflater.from(this).inflate(R.layout.test_toast, null);
//声明Toast
Toast toast = new Toast(this);
//给Toast设置布局
toast.setView(toastRoot);
//设置布局文件里的控件属性
TextView tv = (TextView) toastRoot.findViewById(R.id.toast_notice);
tv.setText("支付宝微信无需另外支付,退款将原路返还!");
//设置弹出时长
toast.setDuration(Toast.LENGTH_LONG);
//弹出Toast
toast.show();

XML布局:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <com.soooft.android.baicaipos.ui.view.custom.WxAliRefundHint
        android:id="@+id/toast_notice"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:background="@drawable/radius_ninety"
        android:gravity="center_vertical|center_horizontal"
        android:text="支付宝微信无需另外支付,退款将原路返还!"
        android:textSize="16sp"
        android:textStyle="bold"
/>
</android.support.constraint.ConstraintLayout>

注意事项:

弹出Toast的高度,在定义TextView的高度时,才会生效,修改父布局的高度不会生效,原因暂时未知

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值