美文网首页
仿ios 风格的Toast

仿ios 风格的Toast

作者: 对影成三人_bac5 | 来源:发表于2018-11-13 17:42 被阅读0次

    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>

    相关文章

      网友评论

          本文标题:仿ios 风格的Toast

          本文链接:https://www.haomeiwen.com/subject/pxilfqtx.html