//获取样式布局
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的高度时,才会生效,修改父布局的高度不会生效,原因暂时未知