自定义Toast

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:gravity="center"
        android:background="#e0000000"
        android:layout_margin="10dip"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_centerInParent="true">
         
        <ProgressBar
            android:layout_gravity="center_vertical"
            style="?android:attr/progressBarStyleSmall"
            android:layout_width="30dp"
            android:layout_height="30dp"/>

        <TextView
            android:layout_marginRight="40dip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:text="正 在 加 载..." 
            android:textColor="#ffffff"/>
        
    </LinearLayout>

</RelativeLayout>

以上是自定义toast的主要布局

//代码如下

 button.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.toast, null);
				Toast toast=new Toast(MainActivity.this);
				toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 0);
				toast.setDuration(1000000000);
				toast.setView(view);
				toast.show();
			}
		});


你可能感兴趣的:(自定义Toast)