1.实现的效果:
2.实现代码my_toast_show_view.xml
shape_toast_rect_corner.xml
ToastUtil
package com.antbyte.listdemo;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class ToastUtil {
//显示弹出信息
public static void ToastMessage(String message) {
Context context = MyApp.mApp;
try {
View toastRoot = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.my_toast_show_view, null);
Toast toast = new Toast(context);
toast.setView(toastRoot);
TextView tv = (TextView) toastRoot.findViewById(R.id.textItem);
tv.setText(message);
toast.setGravity(Gravity.BOTTOM, 0, 0);
toast.show();
} catch (Exception e) {
e.printStackTrace();
}
}
}
MyApp
package com.antbyte.listdemo;
import android.app.Application;
public class MyApp extends Application {
public static MyApp mApp;
@Override
public void onCreate() {
super.onCreate();
mApp = this;
}
}
3.调用方法
ToastUtil.ToastMessage("提示信息");
是不是很简单^_^



