1、类文件
publicclassToastUtil{
privatestaticViewHolder viewHolder;
publicstaticvoidshow(Context context, String msg){
Toast toast =newToast(context);
View layout = View.inflate(context, R.layout.toast,null);
viewHolder =newViewHolder(layout);
layout.setAlpha(0.7f);
toast.setView(layout);
viewHolder.toastTv.setText(" "+ msg +" ");
toast.setGravity(Gravity.FILL_HORIZONTAL,0,0);
toast.show();
}
staticclassViewHolder{
@BindView(R.id.toast_tv) TextView toastTv;
ViewHolder(View view) {
ButterKnife.bind(this, view);
}
}
}
2、布局xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView android:id="@+id/toast_tv"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_gravity="center"
android:background="@drawable/btn_bg_toast"
android:gravity="center"
android:text="asdf"
android:textColor="@color/main_adapter_bg" />
</LinearLayout>
3、shape
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="4dp" />
<stroke android:width="0.3dp"
android:color="@color/toast_bg" />
<solid android:color="@color/toast_bg" />
<corners android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
</shape>
网友评论