仿ios 风格的Toast

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

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

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" />

3、shape

android:shape="rectangle">

android:color="@color/toast_bg" />

android:bottomRightRadius="10dp"

android:topLeftRadius="10dp"

android:topRightRadius="10dp" />

你可能感兴趣的:(仿ios 风格的Toast)