public class MyToast {
private Toast mToast;
private MyToast(Context context, CharSequence text, int duration) {
View v = LayoutInflater.from(context).inflate(R.layout.my_toast, null);
TextView textView = v.findViewById(R.id.textView1);
textView.setText(text);
mToast = new Toast(context);
mToast.setDuration(duration);
mToast.setView(v);
mToast.setGravity(Gravity.CENTER, 0, 0);
}
public static MyToast makeText(Context context, CharSequence text) {
return new MyToast(context, text, Toast.LENGTH_SHORT);
}
public void show() {
if (mToast != null) {
// mToast.setGravity(Gravity.BOTTOM, 0, 260);
mToast.show();
}
}
public void setGravity(int gravity, int xOffset, int yOffset) {
if (mToast != null) {
mToast.setGravity(gravity, xOffset, yOffset);
}
}
}
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape_alpha"
android:gravity="center"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingLeft="30dp"
android:paddingRight="30dp" >
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"/>
注意:本文归作者所有,未经作者允许,不得转载